Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/kvaneesh/for-upstream' into sta…
Browse files Browse the repository at this point in the history
…ging

* remotes/kvaneesh/for-upstream:
  hw/9pfs: fix P9_STATS_GEN handling
  hw/9pfs: make get_st_gen() return ENOTTY error on special files
  hw/9pfs: handle undefined FS_IOC_GETVERSION case in handle_ioc_getversion()
  hw/9pfs: fix error handing in local_ioc_getversion()

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
pm215 committed Feb 10, 2014
2 parents a87f395 + f8b7ee3 commit 702f6df
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
4 changes: 0 additions & 4 deletions hw/9pfs/cofile.c
Expand Up @@ -38,10 +38,6 @@ int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t st_mode,
});
v9fs_path_unlock(s);
}
/* The ioctl may not be supported depending on the path */
if (err == -ENOTTY) {
err = 0;
}
return err;
}

Expand Down
8 changes: 7 additions & 1 deletion hw/9pfs/virtio-9p-handle.c
Expand Up @@ -582,6 +582,7 @@ static int handle_unlinkat(FsContext *ctx, V9fsPath *dir,
static int handle_ioc_getversion(FsContext *ctx, V9fsPath *path,
mode_t st_mode, uint64_t *st_gen)
{
#ifdef FS_IOC_GETVERSION
int err;
V9fsFidOpenState fid_open;

Expand All @@ -590,7 +591,8 @@ static int handle_ioc_getversion(FsContext *ctx, V9fsPath *path,
* We can get fd for regular files and directories only
*/
if (!S_ISREG(st_mode) && !S_ISDIR(st_mode)) {
return 0;
errno = ENOTTY;
return -1;
}
err = handle_open(ctx, path, O_RDONLY, &fid_open);
if (err < 0) {
Expand All @@ -599,6 +601,10 @@ static int handle_ioc_getversion(FsContext *ctx, V9fsPath *path,
err = ioctl(fid_open.fd, FS_IOC_GETVERSION, st_gen);
handle_close(ctx, &fid_open);
return err;
#else
errno = ENOTTY;
return -1;
#endif
}

static int handle_init(FsContext *ctx)
Expand Down
10 changes: 6 additions & 4 deletions hw/9pfs/virtio-9p-local.c
Expand Up @@ -1068,27 +1068,29 @@ static int local_unlinkat(FsContext *ctx, V9fsPath *dir,
static int local_ioc_getversion(FsContext *ctx, V9fsPath *path,
mode_t st_mode, uint64_t *st_gen)
{
int err;
#ifdef FS_IOC_GETVERSION
int err;
V9fsFidOpenState fid_open;

/*
* Do not try to open special files like device nodes, fifos etc
* We can get fd for regular files and directories only
*/
if (!S_ISREG(st_mode) && !S_ISDIR(st_mode)) {
return 0;
errno = ENOTTY;
return -1;
}
err = local_open(ctx, path, O_RDONLY, &fid_open);
if (err < 0) {
return err;
}
err = ioctl(fid_open.fd, FS_IOC_GETVERSION, st_gen);
local_close(ctx, &fid_open);
return err;
#else
err = -ENOTTY;
errno = ENOTTY;
return -1;
#endif
return err;
}

static int local_init(FsContext *ctx)
Expand Down
3 changes: 2 additions & 1 deletion hw/9pfs/virtio-9p-proxy.c
Expand Up @@ -1086,7 +1086,8 @@ static int proxy_ioc_getversion(FsContext *fs_ctx, V9fsPath *path,
* we can get fd for regular files and directories only
*/
if (!S_ISREG(st_mode) && !S_ISDIR(st_mode)) {
return 0;
errno = ENOTTY;
return -1;
}
err = v9fs_request(fs_ctx->private, T_GETVERSION, st_gen, "s", path);
if (err < 0) {
Expand Down
12 changes: 10 additions & 2 deletions hw/9pfs/virtio-9p.c
Expand Up @@ -1080,10 +1080,18 @@ static void v9fs_getattr(void *opaque)
/* fill st_gen if requested and supported by underlying fs */
if (request_mask & P9_STATS_GEN) {
retval = v9fs_co_st_gen(pdu, &fidp->path, stbuf.st_mode, &v9stat_dotl);
if (retval < 0) {
switch (retval) {
case 0:
/* we have valid st_gen: update result mask */
v9stat_dotl.st_result_mask |= P9_STATS_GEN;
break;
case -EINTR:
/* request cancelled, e.g. by Tflush */
goto out;
default:
/* failed to get st_gen: not fatal, ignore */
break;
}
v9stat_dotl.st_result_mask |= P9_STATS_GEN;
}
retval = pdu_marshal(pdu, offset, "A", &v9stat_dotl);
if (retval < 0) {
Expand Down

0 comments on commit 702f6df

Please sign in to comment.