From patchwork Wed Mar 9 12:44:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 8546001 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EEC16C0553 for ; Wed, 9 Mar 2016 12:47:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D0C7520155 for ; Wed, 9 Mar 2016 12:47:41 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AA56D20121 for ; Wed, 9 Mar 2016 12:47:40 +0000 (UTC) Received: from localhost ([::1]:41102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1addWe-0003oU-2h for patchwork-qemu-devel@patchwork.kernel.org; Wed, 09 Mar 2016 07:47:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1addU1-0008Pc-0C for qemu-devel@nongnu.org; Wed, 09 Mar 2016 07:44:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1addTz-0006id-Ev for qemu-devel@nongnu.org; Wed, 09 Mar 2016 07:44:56 -0500 Received: from mail-ob0-x235.google.com ([2607:f8b0:4003:c01::235]:34470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1addTz-0006iZ-7y for qemu-devel@nongnu.org; Wed, 09 Mar 2016 07:44:55 -0500 Received: by mail-ob0-x235.google.com with SMTP id ts10so45182093obc.1 for ; Wed, 09 Mar 2016 04:44:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=2b8+SpzdtX4BCcvWcDnNMOtwGJZ4imByKWNpX8VbOWc=; b=0etK9MHSq9a/T5vOoYfPb8jJjODvPN7zOE1uEDltxuNHXSTfWPES3Q96EMOOH2CApl fMCgyJYWtnr3fwCr1IXpAAO54YI3msktENpAx4mdpvYjGdzHq6IvPyaKefqczedm0xhW /hVC7uqEBNbgUJoq+ahk/+cVWq82J8fF1bF24JC0a34e4fdnQdVIG4mSTK9NWY1JwN8E bYuNOGG3mg5hQWRGMb4LQKTQsoPPwfZIqGRHG3JKPMwKi7pHM4TfCxm0KEHlSMb7/NwU trvB3BXaemAVOpFhRPgm0SoEaNONaU9NL+lFdDPVYVxWjkK3H7ATd9gtJoD33JPYbysf 7Jyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=2b8+SpzdtX4BCcvWcDnNMOtwGJZ4imByKWNpX8VbOWc=; b=BY9x0dloba6CSzEI1iPQoyG7R+2zZ2Ba2lYTIpDPQwo7pt+xpJn8j5TrxVMKdhDMpP gPLS5tqjFIi8Csoi+uxm3M1TmFf+DAECLO46i+Y//+w6aE2Fa1xfUPjou5OJT1PxgBAf P1G+4RqUc0T6upzw7e0cG7a57zoh8HLtF8RfetH8nwyFbaHrWgTjrQExZ0k+p7rHGCc6 HmrAls4ACTZKFdlNk/ITJwb0IfiSNblgJf4hqTzozx1YoxwvvyNx4iFVb0MOQD/M4U3C RdpaS2t1y/qeQ4bGNAQzgLVBoZQuPAgeDgozKF9HBJaLj75hjW6t5WKsQ//NY169Igxv Zg6Q== X-Gm-Message-State: AD7BkJKB6nttkHVZN+UNci18wTrNy22ya0EtOsQKqDAp41aj6Zfw2/FVCzi7yIAgvK7VcmhWx/3X2VUS7wMBAA== MIME-Version: 1.0 X-Received: by 10.182.200.136 with SMTP id js8mr20591621obc.11.1457527494756; Wed, 09 Mar 2016 04:44:54 -0800 (PST) Received: by 10.76.79.73 with HTTP; Wed, 9 Mar 2016 04:44:54 -0800 (PST) In-Reply-To: <1457378754-21649-6-git-send-email-armbru@redhat.com> References: <1457378754-21649-1-git-send-email-armbru@redhat.com> <1457378754-21649-6-git-send-email-armbru@redhat.com> Date: Wed, 9 Mar 2016 13:44:54 +0100 Message-ID: From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= To: Markus Armbruster X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c01::235 Cc: Paolo Bonzini , cam , Claudio Fontana , QEMU , David Marchand Subject: Re: [Qemu-devel] [PATCH v2 05/42] ivshmem-server: Don't overload POSIX shmem and file name X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi On Mon, Mar 7, 2016 at 8:25 PM, Markus Armbruster wrote: > Option -m NAME is interpreted as directory name if we can statfs() it > and its on hugetlbfs. Else it's interpreted as POSIX shared memory > object name. This is nuts. > > Always interpret -m as directory. Create new -M for POSIX shared > memory. Last of -m or -M wins. > > Signed-off-by: Markus Armbruster > --- I don't see why the last should win is a good idea, see attached patch for a possible solution, also changing a few comments. Feel free to squash it in this patch or include it in your series. Reviewed-by: Marc-André Lureau > contrib/ivshmem-server/ivshmem-server.c | 56 ++++++--------------------------- > contrib/ivshmem-server/ivshmem-server.h | 4 ++- > contrib/ivshmem-server/main.c | 15 +++++++-- > tests/ivshmem-test.c | 2 +- > 4 files changed, 27 insertions(+), 50 deletions(-) > > diff --git a/contrib/ivshmem-server/ivshmem-server.c b/contrib/ivshmem-server/ivshmem-server.c > index bfd0fad..41aee35 100644 > --- a/contrib/ivshmem-server/ivshmem-server.c > +++ b/contrib/ivshmem-server/ivshmem-server.c > @@ -12,9 +12,6 @@ > #include > #include > #include > -#ifdef CONFIG_LINUX > -#include > -#endif > > #include "ivshmem-server.h" > > @@ -257,7 +254,8 @@ ivshmem_server_ftruncate(int fd, unsigned shmsize) > /* Init a new ivshmem server */ > int > ivshmem_server_init(IvshmemServer *server, const char *unix_sock_path, > - const char *shm_path, size_t shm_size, unsigned n_vectors, > + const char *shm_path, bool use_shm_open, > + size_t shm_size, unsigned n_vectors, > bool verbose) > { > int ret; > @@ -278,6 +276,7 @@ ivshmem_server_init(IvshmemServer *server, const char *unix_sock_path, > return -1; > } > > + server->use_shm_open = use_shm_open; > server->shm_size = shm_size; > server->n_vectors = n_vectors; > > @@ -286,31 +285,6 @@ ivshmem_server_init(IvshmemServer *server, const char *unix_sock_path, > return 0; > } > > -#ifdef CONFIG_LINUX > - > -#define HUGETLBFS_MAGIC 0x958458f6 > - > -static long gethugepagesize(const char *path) > -{ > - struct statfs fs; > - int ret; > - > - do { > - ret = statfs(path, &fs); > - } while (ret != 0 && errno == EINTR); > - > - if (ret != 0) { > - return -1; > - } > - > - if (fs.f_type != HUGETLBFS_MAGIC) { > - return -1; > - } > - > - return fs.f_bsize; > -} > -#endif > - > /* open shm, create and bind to the unix socket */ > int > ivshmem_server_start(IvshmemServer *server) > @@ -319,27 +293,17 @@ ivshmem_server_start(IvshmemServer *server) > int shm_fd, sock_fd, ret; > > /* open shm file */ > -#ifdef CONFIG_LINUX > - long hpagesize; > - > - hpagesize = gethugepagesize(server->shm_path); > - if (hpagesize < 0 && errno != ENOENT) { > - IVSHMEM_SERVER_DEBUG(server, "cannot stat shm file %s: %s\n", > - server->shm_path, strerror(errno)); > - } > - > - if (hpagesize > 0) { > + if (server->use_shm_open) { > + IVSHMEM_SERVER_DEBUG(server, "Using POSIX shared memory: %s\n", > + server->shm_path); > + shm_fd = shm_open(server->shm_path, O_CREAT|O_RDWR, S_IRWXU); > + } else { > gchar *filename = g_strdup_printf("%s/ivshmem.XXXXXX", server->shm_path); > - IVSHMEM_SERVER_DEBUG(server, "Using hugepages: %s\n", server->shm_path); > + IVSHMEM_SERVER_DEBUG(server, "Using file-backed shared memory: %s\n", > + server->shm_path); > shm_fd = mkstemp(filename); > unlink(filename); > g_free(filename); > - } else > -#endif > - { > - IVSHMEM_SERVER_DEBUG(server, "Using POSIX shared memory: %s\n", > - server->shm_path); > - shm_fd = shm_open(server->shm_path, O_CREAT|O_RDWR, S_IRWXU); > } > > if (shm_fd < 0) { > diff --git a/contrib/ivshmem-server/ivshmem-server.h b/contrib/ivshmem-server/ivshmem-server.h > index e9de8a3..3851639 100644 > --- a/contrib/ivshmem-server/ivshmem-server.h > +++ b/contrib/ivshmem-server/ivshmem-server.h > @@ -66,6 +66,7 @@ typedef struct IvshmemServer { > char unix_sock_path[PATH_MAX]; /**< path to unix socket */ > int sock_fd; /**< unix sock file descriptor */ > char shm_path[PATH_MAX]; /**< path to shm */ > + bool use_shm_open; > size_t shm_size; /**< size of shm */ > int shm_fd; /**< shm file descriptor */ > unsigned n_vectors; /**< number of vectors */ > @@ -89,7 +90,8 @@ typedef struct IvshmemServer { > */ > int > ivshmem_server_init(IvshmemServer *server, const char *unix_sock_path, > - const char *shm_path, size_t shm_size, unsigned n_vectors, > + const char *shm_path, bool use_shm_open, > + size_t shm_size, unsigned n_vectors, > bool verbose); > > /** > diff --git a/contrib/ivshmem-server/main.c b/contrib/ivshmem-server/main.c > index e9b4388..2795db5 100644 > --- a/contrib/ivshmem-server/main.c > +++ b/contrib/ivshmem-server/main.c > @@ -29,6 +29,7 @@ typedef struct IvshmemServerArgs { > const char *pid_file; > const char *unix_socket_path; > const char *shm_path; > + bool use_shm_open; > uint64_t shm_size; > unsigned n_vectors; > } IvshmemServerArgs; > @@ -44,8 +45,9 @@ ivshmem_server_usage(const char *progname) > " default " IVSHMEM_SERVER_DEFAULT_PID_FILE "\n" > " -S : path to the unix socket to listen to\n" > " default " IVSHMEM_SERVER_DEFAULT_UNIX_SOCK_PATH "\n" > - " -m : POSIX shared memory object name or a hugetlbfs mount point\n" > + " -M : POSIX shared memory object to use\n" > " default " IVSHMEM_SERVER_DEFAULT_SHM_PATH "\n" > + " -m : where to create shared memory\n" > " -l : size of shared memory in bytes\n" > " suffixes K, M and G can be used, e.g. 1K means 1024\n" > " default %u\n" > @@ -76,6 +78,7 @@ ivshmem_server_parse_args(IvshmemServerArgs *args, int argc, char *argv[]) > "p:" /* pid_file */ > "S:" /* unix_socket_path */ > "m:" /* shm_path */ > + "M:" /* shm_path */ > "l:" /* shm_size */ > "n:" /* n_vectors */ > )) != -1) { > @@ -102,8 +105,14 @@ ivshmem_server_parse_args(IvshmemServerArgs *args, int argc, char *argv[]) > args->unix_socket_path = optarg; > break; > > + case 'M': /* shm_path */ > + args->shm_path = optarg; > + args->use_shm_open = true; > + break; > + > case 'm': /* shm_path */ > args->shm_path = optarg; > + args->use_shm_open = false; > break; > > case 'l': /* shm_size */ > @@ -199,6 +208,7 @@ main(int argc, char *argv[]) > .pid_file = IVSHMEM_SERVER_DEFAULT_PID_FILE, > .unix_socket_path = IVSHMEM_SERVER_DEFAULT_UNIX_SOCK_PATH, > .shm_path = IVSHMEM_SERVER_DEFAULT_SHM_PATH, > + .use_shm_open = true, > .shm_size = IVSHMEM_SERVER_DEFAULT_SHM_SIZE, > .n_vectors = IVSHMEM_SERVER_DEFAULT_N_VECTORS, > }; > @@ -226,7 +236,8 @@ main(int argc, char *argv[]) > } > > /* init the ivshms structure */ > - if (ivshmem_server_init(&server, args.unix_socket_path, args.shm_path, > + if (ivshmem_server_init(&server, args.unix_socket_path, > + args.shm_path, args.use_shm_open, > args.shm_size, args.n_vectors, args.verbose) < 0) { > fprintf(stderr, "cannot init server\n"); > goto err; > diff --git a/tests/ivshmem-test.c b/tests/ivshmem-test.c > index e184c67..4efa433 100644 > --- a/tests/ivshmem-test.c > +++ b/tests/ivshmem-test.c > @@ -294,7 +294,7 @@ static void test_ivshmem_server(bool msi) > guint64 end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND; > > memset(tmpshmem, 0x42, TMPSHMSIZE); > - ret = ivshmem_server_init(&server, tmpserver, tmpshm, > + ret = ivshmem_server_init(&server, tmpserver, tmpshm, true, > TMPSHMSIZE, nvectors, > g_test_verbose()); > g_assert_cmpint(ret, ==, 0); > -- > 2.4.3 > > From e8112678496fd873ceaa34b3169e516130075ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 8 Mar 2016 20:31:09 +0100 Subject: [PATCH] ivshmem-server: expect either -m or -M MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau --- contrib/ivshmem-server/main.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/contrib/ivshmem-server/main.c b/contrib/ivshmem-server/main.c index 2795db5..368fc67 100644 --- a/contrib/ivshmem-server/main.c +++ b/contrib/ivshmem-server/main.c @@ -77,7 +77,7 @@ ivshmem_server_parse_args(IvshmemServerArgs *args, int argc, char *argv[]) "F" /* foreground */ "p:" /* pid_file */ "S:" /* unix_socket_path */ - "m:" /* shm_path */ + "m:" /* dirname */ "M:" /* shm_path */ "l:" /* shm_size */ "n:" /* n_vectors */ @@ -106,13 +106,15 @@ ivshmem_server_parse_args(IvshmemServerArgs *args, int argc, char *argv[]) break; case 'M': /* shm_path */ - args->shm_path = optarg; - args->use_shm_open = true; - break; + case 'm': /* dirname */ + if (args->shm_path) { + fprintf(stderr, "Please specify either -m or -M.\n"); + ivshmem_server_help(argv[0]); + exit(1); + } - case 'm': /* shm_path */ args->shm_path = optarg; - args->use_shm_open = false; + args->use_shm_open = c == 'M'; break; case 'l': /* shm_size */ @@ -207,7 +209,7 @@ main(int argc, char *argv[]) .foreground = IVSHMEM_SERVER_DEFAULT_FOREGROUND, .pid_file = IVSHMEM_SERVER_DEFAULT_PID_FILE, .unix_socket_path = IVSHMEM_SERVER_DEFAULT_UNIX_SOCK_PATH, - .shm_path = IVSHMEM_SERVER_DEFAULT_SHM_PATH, + .shm_path = NULL, .use_shm_open = true, .shm_size = IVSHMEM_SERVER_DEFAULT_SHM_SIZE, .n_vectors = IVSHMEM_SERVER_DEFAULT_N_VECTORS, @@ -237,8 +239,9 @@ main(int argc, char *argv[]) /* init the ivshms structure */ if (ivshmem_server_init(&server, args.unix_socket_path, - args.shm_path, args.use_shm_open, - args.shm_size, args.n_vectors, args.verbose) < 0) { + args.shm_path ?: IVSHMEM_SERVER_DEFAULT_SHM_PATH, + args.use_shm_open, args.shm_size, args.n_vectors, + args.verbose) < 0) { fprintf(stderr, "cannot init server\n"); goto err; } -- 2.5.0