mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-04 05:40:13 -05:00
readfailover: add new 'readfailover' feature
This commit is contained in:
parent
562295be90
commit
7d436cd231
15 changed files with 510 additions and 115 deletions
|
|
@ -165,20 +165,6 @@ struct fuse_operations
|
|||
*/
|
||||
int (*open) (const char *, struct fuse_file_info *);
|
||||
|
||||
/** Read data from an open file
|
||||
*
|
||||
* Read should return exactly the number of bytes requested except
|
||||
* on EOF or error, otherwise the rest of the data will be
|
||||
* substituted with zeroes. An exception to this is when the
|
||||
* 'direct_io' mount option is specified, in which case the return
|
||||
* value of the read system call will reflect the return value of
|
||||
* this operation.
|
||||
*
|
||||
* Changed in version 2.2
|
||||
*/
|
||||
int (*read) (char *, size_t, off_t,
|
||||
struct fuse_file_info *);
|
||||
|
||||
/** Write data to an open file
|
||||
*
|
||||
* Write should return exactly the number of bytes requested
|
||||
|
|
@ -791,8 +777,6 @@ int fuse_fs_release(struct fuse_fs *fs,
|
|||
struct fuse_file_info *fi);
|
||||
int fuse_fs_open(struct fuse_fs *fs, const char *path,
|
||||
struct fuse_file_info *fi);
|
||||
int fuse_fs_read(struct fuse_fs *fs, char *buf, size_t size,
|
||||
off_t off, struct fuse_file_info *fi);
|
||||
int fuse_fs_read_buf(struct fuse_fs *fs,
|
||||
struct fuse_bufvec **bufp, size_t size, off_t off,
|
||||
struct fuse_file_info *fi);
|
||||
|
|
|
|||
|
|
@ -1617,77 +1617,41 @@ static void fuse_free_buf(struct fuse_bufvec *buf)
|
|||
}
|
||||
}
|
||||
|
||||
int fuse_fs_read_buf(struct fuse_fs *fs,
|
||||
struct fuse_bufvec **bufp, size_t size, off_t off,
|
||||
struct fuse_file_info *fi)
|
||||
{
|
||||
fuse_get_context()->private_data = fs->user_data;
|
||||
if (fs->op.read || fs->op.read_buf) {
|
||||
int res;
|
||||
|
||||
if (fs->debug)
|
||||
fprintf(stderr,
|
||||
"read[%llu] %zu bytes from %llu flags: 0x%x\n",
|
||||
(unsigned long long) fi->fh,
|
||||
size, (unsigned long long) off, fi->flags);
|
||||
|
||||
if (fs->op.read_buf) {
|
||||
res = fs->op.read_buf(bufp, size, off, fi);
|
||||
} else {
|
||||
struct fuse_bufvec *buf;
|
||||
void *mem;
|
||||
|
||||
buf = malloc(sizeof(struct fuse_bufvec));
|
||||
if (buf == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
mem = malloc(size);
|
||||
if (mem == NULL) {
|
||||
free(buf);
|
||||
return -ENOMEM;
|
||||
}
|
||||
*buf = FUSE_BUFVEC_INIT(size);
|
||||
buf->buf[0].mem = mem;
|
||||
*bufp = buf;
|
||||
|
||||
res = fs->op.read(mem, size, off, fi);
|
||||
if (res >= 0)
|
||||
buf->buf[0].size = res;
|
||||
}
|
||||
|
||||
if (fs->debug && res >= 0)
|
||||
fprintf(stderr, " read[%llu] %zu bytes from %llu\n",
|
||||
(unsigned long long) fi->fh,
|
||||
fuse_buf_size(*bufp),
|
||||
(unsigned long long) off);
|
||||
if (res >= 0 && fuse_buf_size(*bufp) > (int) size)
|
||||
fprintf(stderr, "fuse: read too many bytes\n");
|
||||
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
return -ENOSYS;
|
||||
}
|
||||
}
|
||||
|
||||
int fuse_fs_read(struct fuse_fs *fs, char *mem, size_t size,
|
||||
off_t off, struct fuse_file_info *fi)
|
||||
int
|
||||
fuse_fs_read_buf(struct fuse_fs *fs_,
|
||||
struct fuse_bufvec **bufp_,
|
||||
size_t size_,
|
||||
off_t off_,
|
||||
struct fuse_file_info *ffi_)
|
||||
{
|
||||
int res;
|
||||
struct fuse_bufvec *buf = NULL;
|
||||
|
||||
res = fuse_fs_read_buf(fs, &buf, size, off, fi);
|
||||
if (res == 0) {
|
||||
struct fuse_bufvec dst = FUSE_BUFVEC_INIT(size);
|
||||
fuse_get_context()->private_data = fs_->user_data;
|
||||
if(fs_->op.read_buf == NULL)
|
||||
return -ENOSYS;
|
||||
|
||||
dst.buf[0].mem = mem;
|
||||
res = fuse_buf_copy(&dst, buf, 0);
|
||||
}
|
||||
fuse_free_buf(buf);
|
||||
if(fs_->debug)
|
||||
fprintf(stderr,
|
||||
"read[%llu] %zu bytes from %llu flags: 0x%x\n",
|
||||
(unsigned long long)ffi_->fh,
|
||||
size_,
|
||||
(unsigned long long)off_,
|
||||
ffi_->flags);
|
||||
|
||||
return res;
|
||||
res = fs_->op.read_buf(bufp_,size_,off_,ffi_);
|
||||
|
||||
if(fs_->debug && (res >= 0))
|
||||
fprintf(stderr, " read[%llu] %zu bytes from %llu\n",
|
||||
(unsigned long long)ffi_->fh,
|
||||
fuse_buf_size(*bufp_),
|
||||
(unsigned long long)off_);
|
||||
if((res >= 0) && (fuse_buf_size(*bufp_) > (int)size_))
|
||||
fprintf(stderr,"fuse: read too many bytes\n");
|
||||
|
||||
if(res < 0)
|
||||
return res;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fuse_fs_write_buf(struct fuse_fs *fs,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue