Skip to content

Commit

Permalink
hw/9pfs: Use the correct file descriptor in Fsdriver Callback
Browse files Browse the repository at this point in the history
Fsdriver callback that operate on file descriptor need to
differentiate between directory fd and file fd.

Based on the original patch from Sassan Panahinejad <sassan@sassan.me.uk>

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
  • Loading branch information
kvaneesh committed Dec 4, 2011
1 parent 8798d6c commit 8b88827
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
4 changes: 2 additions & 2 deletions fsdev/file-op-9p.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ typedef struct FileOperations
ssize_t (*pwritev)(FsContext *, V9fsFidOpenState *,
const struct iovec *, int, off_t);
int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *);
int (*fstat)(FsContext *, V9fsFidOpenState *, struct stat *);
int (*fstat)(FsContext *, int, V9fsFidOpenState *, struct stat *);
int (*rename)(FsContext *, const char *, const char *);
int (*truncate)(FsContext *, V9fsPath *, off_t);
int (*fsync)(FsContext *, V9fsFidOpenState *, int);
int (*fsync)(FsContext *, int, V9fsFidOpenState *, int);
int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf);
ssize_t (*lgetxattr)(FsContext *, V9fsPath *,
const char *, void *, size_t);
Expand Down
4 changes: 2 additions & 2 deletions hw/9pfs/cofile.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int v9fs_co_fstat(V9fsPDU *pdu, V9fsFidState *fidp, struct stat *stbuf)
}
v9fs_co_run_in_worker(
{
err = s->ops->fstat(&s->ctx, &fidp->fs, stbuf);
err = s->ops->fstat(&s->ctx, fidp->fid_type, &fidp->fs, stbuf);
if (err < 0) {
err = -errno;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ int v9fs_co_fsync(V9fsPDU *pdu, V9fsFidState *fidp, int datasync)
}
v9fs_co_run_in_worker(
{
err = s->ops->fsync(&s->ctx, &fidp->fs, datasync);
err = s->ops->fsync(&s->ctx, fidp->fid_type, &fidp->fs, datasync);
if (err < 0) {
err = -errno;
}
Expand Down
28 changes: 22 additions & 6 deletions hw/9pfs/virtio-9p-handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,17 @@ static int handle_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
return ret;
}

static int handle_fstat(FsContext *fs_ctx, V9fsFidOpenState *fs,
struct stat *stbuf)
static int handle_fstat(FsContext *fs_ctx, int fid_type,
V9fsFidOpenState *fs, struct stat *stbuf)
{
return fstat(fs->fd, stbuf);
int fd;

if (fid_type == P9_FID_DIR) {
fd = dirfd(fs->dir);
} else {
fd = fs->fd;
}
return fstat(fd, stbuf);
}

static int handle_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
Expand Down Expand Up @@ -395,12 +402,21 @@ static int handle_remove(FsContext *ctx, const char *path)
return -1;
}

static int handle_fsync(FsContext *ctx, V9fsFidOpenState *fs, int datasync)
static int handle_fsync(FsContext *ctx, int fid_type,
V9fsFidOpenState *fs, int datasync)
{
int fd;

if (fid_type == P9_FID_DIR) {
fd = dirfd(fs->dir);
} else {
fd = fs->fd;
}

if (datasync) {
return qemu_fdatasync(fs->fd);
return qemu_fdatasync(fd);
} else {
return fsync(fs->fd);
return fsync(fd);
}
}

Expand Down
36 changes: 26 additions & 10 deletions hw/9pfs/virtio-9p-local.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,18 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
return err;
}

static int local_fstat(FsContext *fs_ctx,
static int local_fstat(FsContext *fs_ctx, int fid_type,
V9fsFidOpenState *fs, struct stat *stbuf)
{
int err;
err = fstat(fs->fd, stbuf);
int err, fd;

if (fid_type == P9_FID_DIR) {
fd = dirfd(fs->dir);
} else {
fd = fs->fd;
}

err = fstat(fd, stbuf);
if (err) {
return err;
}
Expand All @@ -381,19 +388,19 @@ static int local_fstat(FsContext *fs_ctx,
mode_t tmp_mode;
dev_t tmp_dev;

if (fgetxattr(fs->fd, "user.virtfs.uid",
if (fgetxattr(fd, "user.virtfs.uid",
&tmp_uid, sizeof(uid_t)) > 0) {
stbuf->st_uid = tmp_uid;
}
if (fgetxattr(fs->fd, "user.virtfs.gid",
if (fgetxattr(fd, "user.virtfs.gid",
&tmp_gid, sizeof(gid_t)) > 0) {
stbuf->st_gid = tmp_gid;
}
if (fgetxattr(fs->fd, "user.virtfs.mode",
if (fgetxattr(fd, "user.virtfs.mode",
&tmp_mode, sizeof(mode_t)) > 0) {
stbuf->st_mode = tmp_mode;
}
if (fgetxattr(fs->fd, "user.virtfs.rdev",
if (fgetxattr(fd, "user.virtfs.rdev",
&tmp_dev, sizeof(dev_t)) > 0) {
stbuf->st_rdev = tmp_dev;
}
Expand Down Expand Up @@ -592,12 +599,21 @@ static int local_remove(FsContext *ctx, const char *path)
return remove(rpath(ctx, path, buffer));
}

static int local_fsync(FsContext *ctx, V9fsFidOpenState *fs, int datasync)
static int local_fsync(FsContext *ctx, int fid_type,
V9fsFidOpenState *fs, int datasync)
{
int fd;

if (fid_type == P9_FID_DIR) {
fd = dirfd(fs->dir);
} else {
fd = fs->fd;
}

if (datasync) {
return qemu_fdatasync(fs->fd);
return qemu_fdatasync(fd);
} else {
return fsync(fs->fd);
return fsync(fd);
}
}

Expand Down
5 changes: 3 additions & 2 deletions hw/9pfs/virtio-9p-synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ static int v9fs_synth_lstat(FsContext *fs_ctx,
return 0;
}

static int v9fs_synth_fstat(FsContext *fs_ctx,
static int v9fs_synth_fstat(FsContext *fs_ctx, int fid_type,
V9fsFidOpenState *fs, struct stat *stbuf)
{
V9fsSynthOpenState *synth_open = fs->private;
Expand Down Expand Up @@ -414,7 +414,8 @@ static int v9fs_synth_remove(FsContext *ctx, const char *path)
return -1;
}

static int v9fs_synth_fsync(FsContext *ctx, V9fsFidOpenState *fs, int datasync)
static int v9fs_synth_fsync(FsContext *ctx, int fid_type,
V9fsFidOpenState *fs, int datasync)
{
errno = ENOSYS;
return 0;
Expand Down

0 comments on commit 8b88827

Please sign in to comment.