From nobody Mon May 6 03:29:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497802818887184.51981389400282; Sun, 18 Jun 2017 09:20:18 -0700 (PDT) Received: from localhost ([::1]:38910 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMcvx-0002im-0m for importer@patchew.org; Sun, 18 Jun 2017 12:20:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40293) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMcul-000295-BK for qemu-devel@nongnu.org; Sun, 18 Jun 2017 12:19:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dMcuk-0008Lz-5H for qemu-devel@nongnu.org; Sun, 18 Jun 2017 12:19:03 -0400 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:36162) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dMcuj-0008Lp-Rp for qemu-devel@nongnu.org; Sun, 18 Jun 2017 12:19:02 -0400 Received: by mail-wr0-x241.google.com with SMTP id 77so10889812wrb.3 for ; Sun, 18 Jun 2017 09:19:01 -0700 (PDT) Received: from localhost.localdomain ([2a02:8108:17c0:1500:2bd4:ef21:bc80:a853]) by smtp.gmail.com with ESMTPSA id 194sm8550476wmx.27.2017.06.18.09.18.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Jun 2017 09:18:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XXJXI3799LayWZ/TlWPGXmIK0NYkQqUjZFNPZSdi4rE=; b=EdTyp1fOp3TbAcJtzqckR9qUFDpwnVwfVS63hfPqgSjOoDUpjKkoLcgPA3+PM3hVMi DKEOmh9117HePN+lsjFzssoscsxpcIGUIJssFC3WZ5HDAF3jxXBqk1i6ZQxIKdk+orD6 D1O18/RGO9SCwz2xscmaorbWEcBiiLyj8TcQDJLBogrLosYJ9c/1G0JkDuK87Ex7W8Sw IPKqnSel4M92fkLom8TfJ2Huq8j8dGMicvPV8AZ+m57+oZDcxvRnulK/RNjFgppHCjlN 0gJArve2Gj8PLs0pqGtRfu2Pjrb1jsfQEXXF9mfX8qACwFVDnMw8qQaYtA19ivePlzCA U2zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XXJXI3799LayWZ/TlWPGXmIK0NYkQqUjZFNPZSdi4rE=; b=l2eY1z6iEL5DeuMvXc9wYsD19QQ5QB2iiF4+sUhOtaGqwPtkr8HAOWD+cMSo9gMWQA 7iBTQIyMUiE50QK5ZPpvFvNQxXRfCHzQvBLf+t7qMFoWR5rbsmbrcfte5tukv1KtC9kr /kR8yxm1wb11U4z248gNkcFCBa/FxEvZtQo4zttY2XI/4li6CXA7nRJ04q0i1miz5Yy8 Ib1xVNWDpZk/4qUlATD0Yf9HFlLcW8d1M6qQqqZ1Rlv1k70lLGxOPk6pf5CeWPvN4Jfn d+7CAWQ1Kb/cENOVzpS5QAS2aCLZp5XVkduEMt9DsTn7iEuyDb3MmNfzGoYrsyz4B1P4 mciw== X-Gm-Message-State: AKS2vOygqqc7NE+ZkGOsNC8ce3Nf27z7y6bbpETZmaictOQdWDVfHgOW Vlww/Jq9ko+fSEcXT0s= X-Received: by 10.223.175.204 with SMTP id y12mr7980099wrd.61.1497802740571; Sun, 18 Jun 2017 09:19:00 -0700 (PDT) From: Tobias Schramm To: qemu-devel@nongnu.org Date: Sun, 18 Jun 2017 18:17:27 +0200 Message-Id: <20170618161727.18404-2-tobleminer@gmail.com> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20170618161727.18404-1-tobleminer@gmail.com> References: <20170618161727.18404-1-tobleminer@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PATCH v3 1/1] Add support for custom fmasks/dmasks in 9ps mapped mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: el13635@mail.ntua.gr, Tobias Schramm , aneesh.kumar@linux.vnet.ibm.com, groug@kaod.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tobias Schramm --- v3: Use unsigned types for umask v2: Adjust patch to QEMU code style fsdev/file-op-9p.h | 4 ++++ fsdev/qemu-fsdev-opts.c | 12 ++++++++++++ hw/9pfs/9p-local.c | 29 +++++++++++++++++++++++++---- hw/9pfs/9p.c | 3 +++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h index 0844a403dc..0ecb1d392b 100644 --- a/fsdev/file-op-9p.h +++ b/fsdev/file-op-9p.h @@ -76,6 +76,8 @@ typedef struct FsDriverEntry { int export_flags; FileOperations *ops; FsThrottle fst; + mode_t fmask; + mode_t dmask; } FsDriverEntry; =20 typedef struct FsContext @@ -88,6 +90,8 @@ typedef struct FsContext FsThrottle *fst; /* fs driver specific data */ void *private; + mode_t fmask; + mode_t dmask; } FsContext; =20 typedef struct V9fsPath { diff --git a/fsdev/qemu-fsdev-opts.c b/fsdev/qemu-fsdev-opts.c index bf5713008a..dd6391edb0 100644 --- a/fsdev/qemu-fsdev-opts.c +++ b/fsdev/qemu-fsdev-opts.c @@ -38,6 +38,12 @@ static QemuOptsList qemu_fsdev_opts =3D { }, { .name =3D "sock_fd", .type =3D QEMU_OPT_NUMBER, + }, { + .name =3D "fmask", + .type =3D QEMU_OPT_STRING, + }, { + .name =3D "dmask", + .type =3D QEMU_OPT_STRING, }, =20 THROTTLE_OPTS, @@ -75,6 +81,12 @@ static QemuOptsList qemu_virtfs_opts =3D { }, { .name =3D "sock_fd", .type =3D QEMU_OPT_NUMBER, + }, { + .name =3D "fmask", + .type =3D QEMU_OPT_STRING, + }, { + .name =3D "dmask", + .type =3D QEMU_OPT_STRING, }, =20 { /*End of list */ } diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 1e78b7c9e9..ef7282e294 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -633,7 +633,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir= _path, =20 if (fs_ctx->export_flags & V9FS_SM_MAPPED || fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { - err =3D mknodat(dirfd, name, SM_LOCAL_MODE_BITS | S_IFREG, 0); + err =3D mknodat(dirfd, name, fs_ctx->fmask | S_IFREG, 0); if (err =3D=3D -1) { goto out; } @@ -685,7 +685,7 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir= _path, =20 if (fs_ctx->export_flags & V9FS_SM_MAPPED || fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { - err =3D mkdirat(dirfd, name, SM_LOCAL_DIR_MODE_BITS); + err =3D mkdirat(dirfd, name, fs_ctx->dmask); if (err =3D=3D -1) { goto out; } @@ -786,7 +786,7 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir= _path, const char *name, /* Determine the security model */ if (fs_ctx->export_flags & V9FS_SM_MAPPED || fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { - fd =3D openat_file(dirfd, name, flags, SM_LOCAL_MODE_BITS); + fd =3D openat_file(dirfd, name, flags, fs_ctx->fmask); if (fd =3D=3D -1) { goto out; } @@ -849,7 +849,7 @@ static int local_symlink(FsContext *fs_ctx, const char = *oldpath, ssize_t oldpath_size, write_size; =20 fd =3D openat_file(dirfd, name, O_CREAT | O_EXCL | O_RDWR, - SM_LOCAL_MODE_BITS); + fs_ctx->fmask); if (fd =3D=3D -1) { goto out; } @@ -1431,6 +1431,9 @@ static int local_parse_opts(QemuOpts *opts, struct Fs= DriverEntry *fse) { const char *sec_model =3D qemu_opt_get(opts, "security_model"); const char *path =3D qemu_opt_get(opts, "path"); + const char *fmask =3D qemu_opt_get(opts, "fmask"); + const char *dmask =3D qemu_opt_get(opts, "dmask"); + unsigned long mask; Error *err =3D NULL; =20 if (!sec_model) { @@ -1469,6 +1472,24 @@ static int local_parse_opts(QemuOpts *opts, struct F= sDriverEntry *fse) =20 fse->path =3D g_strdup(path); =20 + fse->fmask =3D SM_LOCAL_MODE_BITS; + if (fmask) { + if (qemu_strtoul(fmask, NULL, 0, &mask)) { + error_report("Invalid fmask %s specified", fmask); + return -1; + } + fse->fmask =3D ((mode_t)mask) & 0777; + } + + fse->dmask =3D SM_LOCAL_DIR_MODE_BITS; + if (dmask) { + if (qemu_strtoul(dmask, NULL, 0, &mask)) { + error_report("Invalid dmask %s specified", dmask); + return -1; + } + fse->dmask =3D ((mode_t)mask) & 0777; + } + return 0; } =20 diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 96d2683348..40290dbade 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -3533,6 +3533,9 @@ int v9fs_device_realize_common(V9fsState *s, Error **= errp) =20 s->ops =3D fse->ops; =20 + s->ctx.fmask =3D fse->fmask; + s->ctx.dmask =3D fse->dmask; + s->fid_list =3D NULL; qemu_co_rwlock_init(&s->rename_lock); =20 --=20 2.13.1