qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH -V3 7/8] hw/9pfs: Add new virtfs option cache=no


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [PATCH -V3 7/8] hw/9pfs: Add new virtfs option cache=none to skip host page cache
Date: Sun, 13 Mar 2011 17:23:50 +0000

On Sat, Mar 5, 2011 at 5:52 PM, Aneesh Kumar K.V
<address@hidden> wrote:
> cache=none implies the file are opened in the host with O_SYNC open flag

O_SYNC does not bypass the host page cache.  It ensures that writes
only complete once data has been written to the disk.

O_DIRECT is a hint to bypass the host page cache when possible.

A boolean on|off option would be nicer than an option that takes the
special string "none".  For example, direct=on|off.  It also makes the
code nicer by using bools instead of strdup strings that get leaked.

> @@ -2379,6 +2379,8 @@ int main(int argc, char **argv, char **envp)
>                 }
>                 break;
>             case QEMU_OPTION_virtfs: {
> +                const char *cache;
> +                char *arg_cache = NULL;
>                 char *arg_fsdev = NULL;
>                 char *arg_9p = NULL;
>                 int len = 0;
> @@ -2404,7 +2406,18 @@ int main(int argc, char **argv, char **envp)
>                     exit(1);
>                 }
>
> +                cache = qemu_opt_get(opts, "cache");
> +                if (cache) {
> +                    len = strlen(",cache=");
> +                    len += strlen(cache);
> +                    arg_cache = qemu_malloc(len+1);
> +                    snprintf(arg_cache, (len+1), ",cache=%s", cache);
> +                } else {
> +                    arg_cache = (char *)"";
> +                }
> +
>                 len = strlen(",id=,path=,security_model=");
> +                len += strlen(arg_cache);
>                 len += strlen(qemu_opt_get(opts, "fstype"));
>                 len += strlen(qemu_opt_get(opts, "mount_tag"));
>                 len += strlen(qemu_opt_get(opts, "path"));
> @@ -2412,20 +2425,22 @@ int main(int argc, char **argv, char **envp)
>                 arg_fsdev = qemu_malloc((len + 1) * sizeof(*arg_fsdev));
>
>                 snprintf(arg_fsdev, (len + 1) * sizeof(*arg_fsdev),
> -                         "%s,id=%s,path=%s,security_model=%s",
> +                         "%s,id=%s,path=%s,security_model=%s%s",
>                          qemu_opt_get(opts, "fstype"),
>                          qemu_opt_get(opts, "mount_tag"),
>                          qemu_opt_get(opts, "path"),
> -                         qemu_opt_get(opts, "security_model"));
> +                         qemu_opt_get(opts, "security_model"),
> +                         arg_cache);
>
>                 len = strlen("virtio-9p-pci,fsdev=,mount_tag=");
>                 len += 2*strlen(qemu_opt_get(opts, "mount_tag"));
>                 arg_9p = qemu_malloc((len + 1) * sizeof(*arg_9p));
>
>                 snprintf(arg_9p, (len + 1) * sizeof(*arg_9p),
> -                         "virtio-9p-pci,fsdev=%s,mount_tag=%s",
> +                         "virtio-9p-pci,fsdev=%s,mount_tag=%s%s",
> +                         qemu_opt_get(opts, "mount_tag"),
>                          qemu_opt_get(opts, "mount_tag"),
> -                         qemu_opt_get(opts, "mount_tag"));
> +                         arg_cache);
>
>                 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev, 1)) {
>                     fprintf(stderr, "parse error [fsdev]: %s\n", optarg);

arg_cache is leaked.

Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]