All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: "M. Mohan Kumar" <mohan@in.ibm.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] hw/9pfs: Handle Security model parsing
Date: Wed, 12 Oct 2011 19:46:48 +0530	[thread overview]
Message-ID: <87ipnuuwfj.fsf@linux.vnet.ibm.com> (raw)
In-Reply-To: <1318406056-17026-1-git-send-email-mohan@in.ibm.com>

On Wed, 12 Oct 2011 13:24:16 +0530, "M. Mohan Kumar" <mohan@in.ibm.com> wrote:
> Security model is needed only for 'local' fs driver.

Can you also cleanup that fstype -> fsdriver rename ? fsdriver seems
more appropriate.

> 
> Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
> ---
>  fsdev/qemu-fsdev.c         |    6 +----
>  fsdev/qemu-fsdev.h         |    1 +
>  hw/9pfs/virtio-9p-device.c |   47 ++++++++++++++++++++++---------------------
>  vl.c                       |   20 +++++++++++++++--
>  4 files changed, 43 insertions(+), 31 deletions(-)
> 
> diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c
> index 36db127..d08ba9c 100644
> --- a/fsdev/qemu-fsdev.c
> +++ b/fsdev/qemu-fsdev.c
> @@ -58,11 +58,6 @@ int qemu_fsdev_add(QemuOpts *opts)
>          return -1;
>      }
> 
> -    if (!sec_model) {
> -        fprintf(stderr, "fsdev: No security_model specified.\n");
> -        return -1;
> -    }
> -
>      if (!path) {
>          fprintf(stderr, "fsdev: No path specified.\n");
>          return -1;
> @@ -72,6 +67,7 @@ int qemu_fsdev_add(QemuOpts *opts)
> 
>      fsle->fse.fsdev_id = g_strdup(fsdev_id);
>      fsle->fse.path = g_strdup(path);
> +    fsle->fse.fsdriver = g_strdup(fstype);

Why use it as a string ? Why can't this again be an export_flag. That
would help us to avoid that strdup 


>      fsle->fse.security_model = g_strdup(sec_model);
>      fsle->fse.ops = FsTypes[i].ops;
>      fsle->fse.cache_flags = 0;
> diff --git a/fsdev/qemu-fsdev.h b/fsdev/qemu-fsdev.h
> index 9c440f2..0f67880 100644
> --- a/fsdev/qemu-fsdev.h
> +++ b/fsdev/qemu-fsdev.h
> @@ -40,6 +40,7 @@ typedef struct FsTypeTable {
>  typedef struct FsTypeEntry {
>      char *fsdev_id;
>      char *path;
> +    char *fsdriver;
>      char *security_model;
>      int cache_flags;
>      FileOperations *ops;
> diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
> index aac58ad..1846e36 100644
> --- a/hw/9pfs/virtio-9p-device.c
> +++ b/hw/9pfs/virtio-9p-device.c
> @@ -83,29 +83,30 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
>          exit(1);
>      }
> 
> -    if (!strcmp(fse->security_model, "passthrough")) {
> -        /* Files on the Fileserver set to client user credentials */
> -        s->ctx.fs_sm = SM_PASSTHROUGH;
> -        s->ctx.xops = passthrough_xattr_ops;
> -    } else if (!strcmp(fse->security_model, "mapped")) {
> -        /* Files on the fileserver are set to QEMU credentials.
> -         * Client user credentials are saved in extended attributes.
> -         */
> -        s->ctx.fs_sm = SM_MAPPED;
> -        s->ctx.xops = mapped_xattr_ops;
> -    } else if (!strcmp(fse->security_model, "none")) {
> -        /*
> -         * Files on the fileserver are set to QEMU credentials.
> -         */
> -        s->ctx.fs_sm = SM_NONE;
> -        s->ctx.xops = none_xattr_ops;
> -    } else {
> -        fprintf(stderr, "Default to security_model=none. You may want"
> -                " enable advanced security model using "
> -                "security option:\n\t security_model=passthrough\n\t "
> -                "security_model=mapped\n");
> -        s->ctx.fs_sm = SM_NONE;
> -        s->ctx.xops = none_xattr_ops;
> +    /* security models is needed only for local fs driver */
> +    if (!strcmp(fse->fsdriver, "local")) {
> +        if (!strcmp(fse->security_model, "passthrough")) {
> +            /* Files on the Fileserver set to client user credentials */
> +            s->ctx.fs_sm = SM_PASSTHROUGH;
> +            s->ctx.xops = passthrough_xattr_ops;
> +        } else if (!strcmp(fse->security_model, "mapped")) {
> +            /* Files on the fileserver are set to QEMU credentials.
> +            * Client user credentials are saved in extended attributes.
> +            */
> +            s->ctx.fs_sm = SM_MAPPED;
> +            s->ctx.xops = mapped_xattr_ops;
> +        } else if (!strcmp(fse->security_model, "none")) {
> +            /*
> +            * Files on the fileserver are set to QEMU credentials.
> +            */
> +            s->ctx.fs_sm = SM_NONE;
> +            s->ctx.xops = none_xattr_ops;
> +        } else {
> +            fprintf(stderr, "Invalid security_model %s specified.\n"
> +                    "Available security models are:\t "
> +                    "passthrough,mapped or none\n", fse->security_model);
> +            exit(1);
> +        }
>      }
> 
>      s->ctx.cache_flags = fse->cache_flags;
> diff --git a/vl.c b/vl.c
> index 6760e39..a961fa3 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2795,6 +2795,7 @@ int main(int argc, char **argv, char **envp)
>                  QemuOpts *fsdev;
>                  QemuOpts *device;
>                  const char *cache;
> +                const char *fsdriver;
> 
>                  olist = qemu_find_opts("virtfs");
>                  if (!olist) {
> @@ -2809,13 +2810,26 @@ int main(int argc, char **argv, char **envp)
> 
>                  if (qemu_opt_get(opts, "fstype") == NULL ||
>                          qemu_opt_get(opts, "mount_tag") == NULL ||
> -                        qemu_opt_get(opts, "path") == NULL ||
> -                        qemu_opt_get(opts, "security_model") == NULL) {
> +                        qemu_opt_get(opts, "path") == NULL) {
>                      fprintf(stderr, "Usage: -virtfs fstype,path=/share_path/,"
> -                            "security_model=[mapped|passthrough|none],"
> +
>                          "{security_model=[mapped|passthrough|none]},"

That should be
                         [security_model=....]                             


>                              "mount_tag=tag.\n");
>                      exit(1);
>                  }
> +                fsdriver = qemu_opt_get(opts, "fstype");
> +                /* security model is mandatory for local fs driver */
> +                if (!strcmp(fsdriver,"local") &&
> +                                !qemu_opt_get(opts,"security_model")) {
> +                    fprintf(stderr, "security model not specified for local"
> +                                   " fs driver\n");
> +                    exit(1);
> +                }
> +                if (strcmp(fsdriver,"local") &&
> +                                qemu_opt_get(opts,"security_model")) {
> +                    fprintf(stderr, "security model is not needed for %s"
> +                                   " fs driver\n", fsdriver);
> +                    exit(1);
> +                }
> 
>                  fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
>                                           qemu_opt_get(opts, "mount_tag"), 1);

Also needs a documentation update.

-aneesh

  parent reply	other threads:[~2011-10-12 14:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-12  7:54 [Qemu-devel] [PATCH] hw/9pfs: Handle Security model parsing M. Mohan Kumar
2011-10-12  8:28 ` Daniel P. Berrange
2011-10-12 14:22   ` Aneesh Kumar K.V
2011-10-12 15:35   ` M. Mohan Kumar
2011-10-12 16:07     ` Daniel P. Berrange
2011-10-14  4:24       ` M. Mohan Kumar
2011-10-12 14:16 ` Aneesh Kumar K.V [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-10-14 12:06 M. Mohan Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ipnuuwfj.fsf@linux.vnet.ibm.com \
    --to=aneesh.kumar@linux.vnet.ibm.com \
    --cc=mohan@in.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.