Commit ee98a6b0 authored by Peter Maydell's avatar Peter Maydell
Browse files

Merge remote-tracking branch 'remotes/gkurz/tags/for-upstream' into staging



- Aneesh no longer listed in MAINTAINERS,
- deprecation of the handle backend,
- improved error reporting, especially when the local backend fails to
  open the VirtFS root,
- virtio-9p-test to behave more like a real virtio guest driver: set
  DRIVER_OK when ready to use the device and process the used ring
  for completed requests,
- cosmetic fixes (mostly coding style related).

# gpg: Signature made Mon 08 Jan 2018 10:19:18 GMT
# gpg:                using RSA key 0x71D4D5E5822F73D6
# gpg: Good signature from "Greg Kurz <groug@kaod.org>"
# gpg:                 aka "Gregory Kurz <gregory.kurz@free.fr>"
# gpg:                 aka "[jpeg image of size 3330]"
# Primary key fingerprint: B482 8BAF 9431 40CE F2A3  4910 71D4 D5E5 822F 73D6

* remotes/gkurz/tags/for-upstream:
  MAINTAINERS: Drop Aneesh as 9pfs maintainer
  9pfs: deprecate handle backend
  fsdev: improve error handling of backend init
  fsdev: improve error handling of backend opts parsing
  tests: virtio-9p: set DRIVER_OK before using the device
  tests: virtio-9p: fix ISR dependence
  9pfs: make pdu_marshal() and pdu_unmarshal() static functions
  9pfs: fix error path in pdu_submit()
  9pfs: fix type in *_parse_opts declarations
  9pfs: handle: fix type definition
  9pfs: fix some type definitions
  fsdev: fix some type definitions
  9pfs: fix XattrOperations typedef
  virtio-9p: move unrealize/realize after virtio_9p_transport definition

Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
parents 232e5537 ffcfb446
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -1083,13 +1083,11 @@ F: include/hw/virtio/
F: tests/virtio-balloon-test.c

virtio-9p
M: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
M: Greg Kurz <groug@kaod.org>
S: Supported
F: hw/9pfs/
F: fsdev/
F: tests/virtio-9p-test.c
T: git git://github.com/kvaneesh/QEMU.git
T: git git://github.com/gkurz/qemu.git 9p-next

virtio-blk
+17 −19
Original line number Diff line number Diff line
@@ -22,22 +22,19 @@
#define SM_LOCAL_MODE_BITS    0600
#define SM_LOCAL_DIR_MODE_BITS    0700

typedef struct FsCred
{
typedef struct FsCred {
    uid_t   fc_uid;
    gid_t   fc_gid;
    mode_t  fc_mode;
    dev_t   fc_rdev;
} FsCred;

struct xattr_operations;
struct FsContext;
struct V9fsPath;
typedef struct FsContext FsContext;
typedef struct V9fsPath V9fsPath;

typedef struct extended_ops {
    int (*get_st_gen)(struct FsContext *, struct V9fsPath *,
                      mode_t, uint64_t *);
} extended_ops;
typedef struct ExtendedOps {
    int (*get_st_gen)(FsContext *, V9fsPath *, mode_t, uint64_t *);
} ExtendedOps;

/* export flags */
#define V9FS_IMMEDIATE_WRITEOUT     0x00000001
@@ -67,6 +64,8 @@ typedef struct extended_ops {


typedef struct FileOperations FileOperations;
typedef struct XattrOperations XattrOperations;

/*
 * Structure to store the various fsdev's passed through command line.
 */
@@ -80,24 +79,23 @@ typedef struct FsDriverEntry {
    mode_t dmode;
} FsDriverEntry;

typedef struct FsContext
{
struct FsContext {
    uid_t uid;
    char *fs_root;
    int export_flags;
    struct xattr_operations **xops;
    struct extended_ops exops;
    XattrOperations **xops;
    ExtendedOps exops;
    FsThrottle *fst;
    /* fs driver specific data */
    void *private;
    mode_t fmode;
    mode_t dmode;
} FsContext;
};

typedef struct V9fsPath {
struct V9fsPath {
    uint16_t size;
    char *data;
} V9fsPath;
};

typedef union V9fsFidOpenState V9fsFidOpenState;

@@ -105,9 +103,9 @@ void cred_init(FsCred *);

struct FileOperations
{
    int (*parse_opts)(QemuOpts *, struct FsDriverEntry *);
    int (*init)(struct FsContext *);
    void (*cleanup)(struct FsContext *);
    int (*parse_opts)(QemuOpts *, FsDriverEntry *, Error **errp);
    int (*init)(FsContext *, Error **errp);
    void (*cleanup)(FsContext *);
    int (*lstat)(FsContext *, V9fsPath *, struct stat *);
    ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t);
    int (*chmod)(FsContext *, V9fsPath *, FsCred *);
+3 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ int qemu_fsdev_add(QemuOpts *opts)
    const char *fsdriver = qemu_opt_get(opts, "fsdriver");
    const char *writeout = qemu_opt_get(opts, "writeout");
    bool ro = qemu_opt_get_bool(opts, "readonly", 0);
    Error *local_err = NULL;

    if (!fsdev_id) {
        error_report("fsdev: No id specified");
@@ -74,7 +75,8 @@ int qemu_fsdev_add(QemuOpts *opts)
    }

    if (fsle->fse.ops->parse_opts) {
        if (fsle->fse.ops->parse_opts(opts, &fsle->fse)) {
        if (fsle->fse.ops->parse_opts(opts, &fsle->fse, &local_err)) {
            error_report_err(local_err);
            g_free(fsle->fse.fsdev_id);
            g_free(fsle);
            return -1;
+28 −26
Original line number Diff line number Diff line
@@ -41,10 +41,10 @@
#define BTRFS_SUPER_MAGIC 0x9123683E
#endif

struct handle_data {
typedef struct HandleData {
    int mountfd;
    int handle_bytes;
};
} HandleData;

static inline int name_to_handle(int dirfd, const char *name,
                                 struct file_handle *fh, int *mnt_id, int flags)
@@ -79,7 +79,7 @@ static int handle_lstat(FsContext *fs_ctx, V9fsPath *fs_path,
                        struct stat *stbuf)
{
    int fd, ret;
    struct handle_data *data = (struct handle_data *)fs_ctx->private;
    HandleData *data = (HandleData *) fs_ctx->private;

    fd = open_by_handle(data->mountfd, fs_path->data, O_PATH);
    if (fd < 0) {
@@ -94,7 +94,7 @@ static ssize_t handle_readlink(FsContext *fs_ctx, V9fsPath *fs_path,
                               char *buf, size_t bufsz)
{
    int fd, ret;
    struct handle_data *data = (struct handle_data *)fs_ctx->private;
    HandleData *data = (HandleData *) fs_ctx->private;

    fd = open_by_handle(data->mountfd, fs_path->data, O_PATH);
    if (fd < 0) {
@@ -118,7 +118,7 @@ static int handle_closedir(FsContext *ctx, V9fsFidOpenState *fs)
static int handle_open(FsContext *ctx, V9fsPath *fs_path,
                       int flags, V9fsFidOpenState *fs)
{
    struct handle_data *data = (struct handle_data *)ctx->private;
    HandleData *data = (HandleData *) ctx->private;

    fs->fd = open_by_handle(data->mountfd, fs_path->data, flags);
    return fs->fd;
@@ -207,7 +207,7 @@ static ssize_t handle_pwritev(FsContext *ctx, V9fsFidOpenState *fs,
static int handle_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
{
    int fd, ret;
    struct handle_data *data = (struct handle_data *)fs_ctx->private;
    HandleData *data = (HandleData *) fs_ctx->private;

    fd = open_by_handle(data->mountfd, fs_path->data, O_NONBLOCK);
    if (fd < 0) {
@@ -222,7 +222,7 @@ static int handle_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
                       const char *name, FsCred *credp)
{
    int dirfd, ret;
    struct handle_data *data = (struct handle_data *)fs_ctx->private;
    HandleData *data = (HandleData *) fs_ctx->private;

    dirfd = open_by_handle(data->mountfd, dir_path->data, O_PATH);
    if (dirfd < 0) {
@@ -240,7 +240,7 @@ static int handle_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
                       const char *name, FsCred *credp)
{
    int dirfd, ret;
    struct handle_data *data = (struct handle_data *)fs_ctx->private;
    HandleData *data = (HandleData *) fs_ctx->private;

    dirfd = open_by_handle(data->mountfd, dir_path->data, O_PATH);
    if (dirfd < 0) {
@@ -272,7 +272,7 @@ static int handle_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
{
    int ret;
    int dirfd, fd;
    struct handle_data *data = (struct handle_data *)fs_ctx->private;
    HandleData *data = (HandleData *) fs_ctx->private;

    dirfd = open_by_handle(data->mountfd, dir_path->data, O_PATH);
    if (dirfd < 0) {
@@ -297,7 +297,7 @@ static int handle_symlink(FsContext *fs_ctx, const char *oldpath,
                          V9fsPath *dir_path, const char *name, FsCred *credp)
{
    int fd, dirfd, ret;
    struct handle_data *data = (struct handle_data *)fs_ctx->private;
    HandleData *data = (HandleData *) fs_ctx->private;

    dirfd = open_by_handle(data->mountfd, dir_path->data, O_PATH);
    if (dirfd < 0) {
@@ -322,7 +322,7 @@ static int handle_link(FsContext *ctx, V9fsPath *oldpath,
                       V9fsPath *dirpath, const char *name)
{
    int oldfd, newdirfd, ret;
    struct handle_data *data = (struct handle_data *)ctx->private;
    HandleData *data = (HandleData *) ctx->private;

    oldfd = open_by_handle(data->mountfd, oldpath->data, O_PATH);
    if (oldfd < 0) {
@@ -342,7 +342,7 @@ static int handle_link(FsContext *ctx, V9fsPath *oldpath,
static int handle_truncate(FsContext *ctx, V9fsPath *fs_path, off_t size)
{
    int fd, ret;
    struct handle_data *data = (struct handle_data *)ctx->private;
    HandleData *data = (HandleData *) ctx->private;

    fd = open_by_handle(data->mountfd, fs_path->data, O_NONBLOCK | O_WRONLY);
    if (fd < 0) {
@@ -363,7 +363,7 @@ static int handle_rename(FsContext *ctx, const char *oldpath,
static int handle_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
{
    int fd, ret;
    struct handle_data *data = (struct handle_data *)fs_ctx->private;
    HandleData *data = (HandleData *) fs_ctx->private;

    fd = open_by_handle(data->mountfd, fs_path->data, O_PATH);
    if (fd < 0) {
@@ -379,7 +379,7 @@ static int handle_utimensat(FsContext *ctx, V9fsPath *fs_path,
{
    int ret;
    int fd;
    struct handle_data *data = (struct handle_data *)ctx->private;
    HandleData *data = (HandleData *) ctx->private;

    fd = open_by_handle(data->mountfd, fs_path->data, O_NONBLOCK);
    if (fd < 0) {
@@ -418,7 +418,7 @@ static int handle_statfs(FsContext *ctx, V9fsPath *fs_path,
                         struct statfs *stbuf)
{
    int fd, ret;
    struct handle_data *data = (struct handle_data *)ctx->private;
    HandleData *data = (HandleData *) ctx->private;

    fd = open_by_handle(data->mountfd, fs_path->data, O_NONBLOCK);
    if (fd < 0) {
@@ -433,7 +433,7 @@ static ssize_t handle_lgetxattr(FsContext *ctx, V9fsPath *fs_path,
                                const char *name, void *value, size_t size)
{
    int fd, ret;
    struct handle_data *data = (struct handle_data *)ctx->private;
    HandleData *data = (HandleData *) ctx->private;

    fd = open_by_handle(data->mountfd, fs_path->data, O_NONBLOCK);
    if (fd < 0) {
@@ -448,7 +448,7 @@ static ssize_t handle_llistxattr(FsContext *ctx, V9fsPath *fs_path,
                                 void *value, size_t size)
{
    int fd, ret;
    struct handle_data *data = (struct handle_data *)ctx->private;
    HandleData *data = (HandleData *) ctx->private;

    fd = open_by_handle(data->mountfd, fs_path->data, O_NONBLOCK);
    if (fd < 0) {
@@ -463,7 +463,7 @@ static int handle_lsetxattr(FsContext *ctx, V9fsPath *fs_path, const char *name,
                            void *value, size_t size, int flags)
{
    int fd, ret;
    struct handle_data *data = (struct handle_data *)ctx->private;
    HandleData *data = (HandleData *) ctx->private;

    fd = open_by_handle(data->mountfd, fs_path->data, O_NONBLOCK);
    if (fd < 0) {
@@ -478,7 +478,7 @@ static int handle_lremovexattr(FsContext *ctx, V9fsPath *fs_path,
                               const char *name)
{
    int fd, ret;
    struct handle_data *data = (struct handle_data *)ctx->private;
    HandleData *data = (HandleData *) ctx->private;

    fd = open_by_handle(data->mountfd, fs_path->data, O_NONBLOCK);
    if (fd < 0) {
@@ -495,7 +495,7 @@ static int handle_name_to_path(FsContext *ctx, V9fsPath *dir_path,
    char *buffer;
    struct file_handle *fh;
    int dirfd, ret, mnt_id;
    struct handle_data *data = (struct handle_data *)ctx->private;
    HandleData *data = (HandleData *) ctx->private;

    /* "." and ".." are not allowed */
    if (!strcmp(name, ".") || !strcmp(name, "..")) {
@@ -536,7 +536,7 @@ static int handle_renameat(FsContext *ctx, V9fsPath *olddir,
                           const char *new_name)
{
    int olddirfd, newdirfd, ret;
    struct handle_data *data = (struct handle_data *)ctx->private;
    HandleData *data = (HandleData *) ctx->private;

    olddirfd = open_by_handle(data->mountfd, olddir->data, O_PATH);
    if (olddirfd < 0) {
@@ -557,7 +557,7 @@ static int handle_unlinkat(FsContext *ctx, V9fsPath *dir,
                           const char *name, int flags)
{
    int dirfd, ret;
    struct handle_data *data = (struct handle_data *)ctx->private;
    HandleData *data = (HandleData *) ctx->private;
    int rflags;

    dirfd = open_by_handle(data->mountfd, dir->data, O_PATH);
@@ -604,12 +604,12 @@ static int handle_ioc_getversion(FsContext *ctx, V9fsPath *path,
#endif
}

static int handle_init(FsContext *ctx)
static int handle_init(FsContext *ctx, Error **errp)
{
    int ret, mnt_id;
    struct statfs stbuf;
    struct file_handle fh;
    struct handle_data *data = g_malloc(sizeof(struct handle_data));
    HandleData *data = g_malloc(sizeof(HandleData));

    data->mountfd = open(ctx->fs_root, O_DIRECTORY);
    if (data->mountfd < 0) {
@@ -646,17 +646,19 @@ out:

static void handle_cleanup(FsContext *ctx)
{
    struct handle_data *data = ctx->private;
    HandleData *data = ctx->private;

    close(data->mountfd);
    g_free(data);
}

static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse)
static int handle_parse_opts(QemuOpts *opts, FsDriverEntry *fse, Error **errp)
{
    const char *sec_model = qemu_opt_get(opts, "security_model");
    const char *path = qemu_opt_get(opts, "path");

    warn_report("handle backend is deprecated");

    if (sec_model) {
        error_report("Invalid argument security_model specified with handle fsdriver");
        return -1;
+21 −15
Original line number Diff line number Diff line
@@ -1400,13 +1400,14 @@ static int local_ioc_getversion(FsContext *ctx, V9fsPath *path,
#endif
}

static int local_init(FsContext *ctx)
static int local_init(FsContext *ctx, Error **errp)
{
    struct statfs stbuf;
    LocalData *data = g_malloc(sizeof(*data));

    data->mountfd = open(ctx->fs_root, O_DIRECTORY | O_RDONLY);
    if (data->mountfd == -1) {
        error_setg_errno(errp, errno, "failed to open '%s'", ctx->fs_root);
        goto err;
    }

@@ -1459,16 +1460,21 @@ static void local_cleanup(FsContext *ctx)
    g_free(data);
}

static int local_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse)
static void error_append_security_model_hint(Error **errp)
{
    error_append_hint(errp, "Valid options are: security_model="
                      "[passthrough|mapped-xattr|mapped-file|none]\n");
}

static int local_parse_opts(QemuOpts *opts, FsDriverEntry *fse, Error **errp)
{
    const char *sec_model = qemu_opt_get(opts, "security_model");
    const char *path = qemu_opt_get(opts, "path");
    Error *err = NULL;
    Error *local_err = NULL;

    if (!sec_model) {
        error_report("Security model not specified, local fs needs security model");
        error_printf("valid options are:"
                     "\tsecurity_model=[passthrough|mapped-xattr|mapped-file|none]\n");
        error_setg(errp, "security_model property not set");
        error_append_security_model_hint(errp);
        return -1;
    }

@@ -1482,20 +1488,20 @@ static int local_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse)
    } else if (!strcmp(sec_model, "mapped-file")) {
        fse->export_flags |= V9FS_SM_MAPPED_FILE;
    } else {
        error_report("Invalid security model %s specified", sec_model);
        error_printf("valid options are:"
                     "\t[passthrough|mapped-xattr|mapped-file|none]\n");
        error_setg(errp, "invalid security_model property '%s'", sec_model);
        error_append_security_model_hint(errp);
        return -1;
    }

    if (!path) {
        error_report("fsdev: No path specified");
        error_setg(errp, "path property not set");
        return -1;
    }

    fsdev_throttle_parse_opts(opts, &fse->fst, &err);
    if (err) {
        error_reportf_err(err, "Throttle configuration is not valid: ");
    fsdev_throttle_parse_opts(opts, &fse->fst, &local_err);
    if (local_err) {
        error_propagate(errp, local_err);
        error_prepend(errp, "invalid throttle configuration: ");
        return -1;
    }

@@ -1507,11 +1513,11 @@ static int local_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse)
            qemu_opt_get_number(opts, "dmode", SM_LOCAL_DIR_MODE_BITS) & 0777;
    } else {
        if (qemu_opt_find(opts, "fmode")) {
            error_report("fmode is only valid for mapped 9p modes");
            error_setg(errp, "fmode is only valid for mapped security modes");
            return -1;
        }
        if (qemu_opt_find(opts, "dmode")) {
            error_report("dmode is only valid for mapped 9p modes");
            error_setg(errp, "dmode is only valid for mapped security modes");
            return -1;
        }
    }
Loading