From nobody Fri May 3 04:54:33 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 1497774723412942.0905432762984; Sun, 18 Jun 2017 01:32:03 -0700 (PDT) Received: from localhost ([::1]:37539 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMVcn-0006Xk-Qt for importer@patchew.org; Sun, 18 Jun 2017 04:32:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMVaq-0005dj-Tr for qemu-devel@nongnu.org; Sun, 18 Jun 2017 04:30:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dMVap-000591-QZ for qemu-devel@nongnu.org; Sun, 18 Jun 2017 04:30:00 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:35007) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dMVap-000581-Gd for qemu-devel@nongnu.org; Sun, 18 Jun 2017 04:29:59 -0400 Received: by mail-wm0-x242.google.com with SMTP id d64so11817573wmf.2 for ; Sun, 18 Jun 2017 01:29:59 -0700 (PDT) Received: from localhost.localdomain ([2a02:8108:17c0:1500:2bd4:ef21:bc80:a853]) by smtp.gmail.com with ESMTPSA id f21sm10886704wra.5.2017.06.18.01.29.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Jun 2017 01:29:57 -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=IEzJn6udv9d6cTAmV3CIzQlwjd/DMfizQFzjDJJLl8k=; b=HqZ387Ba3XZu1ClmNS/8M7KvVbHNCYN4yifxqOAeBJwstv+jQSxZxmrHATGR4iTXe4 VRlJTCO5vADTwAaVQfqocmYDE4MeKPi86wnkexXaiudRR4j8HrRo/UyGs0rtI5LkHPtd 4sCqTiNmF5Sw41/KRahfiHCVpe8Z2IwiwtdkWn2VHyXxtThAVzkM69ckeSeKwEizXTlb RZEFUU7U5Wc4Sa8jHjkfWjxnDiqmmpQ5mWknYcuwvMbjyMu3jRtcHKNXL3Xnj1hLVu0+ ijmU2SoKYGly8Jzj+MIN8zjJqxO4sOIv/cF+kTEuFtQO8JNgIiswGOxvl5gtbX2Thtth o/Jw== 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=IEzJn6udv9d6cTAmV3CIzQlwjd/DMfizQFzjDJJLl8k=; b=RzxTptnQTVHj4u0aDkVJYB4evK8iab3kvHV5EgsoPDUIFw+IX0YulfbVgNKMf2HrLp 0nackG0oexYMFUzAGYbqEJ/5Sor3uRNh+nNwGgu7i39Kogqwh5Kp3J0KfJR5r+RmzY/5 eAhKVPr+TneSrAfUhH8AA9DV/sKtipagyDzsTrjAWZ0CVWAj5tQR2iyd+SnSQHaWcVU4 chzG4oS9epP2BC7PEMJPHiuYuMg2Eqju0W3G96xCRQfgwS1GWPKRu0CNCnEMPvhuXjoI c+obg/IyIOF4OOGzcKUqj8XDkodXRBwMXotdp+ucmUx6XbdJN5BapXfI9A7epVmxUr1W GKLQ== X-Gm-Message-State: AKS2vOzMwaAeARX4ZoHIq+K0IYmXnNmLcLx8C72yBGjBMvs4ctd62vOg 2KFSBkKSM1nMk99b X-Received: by 10.28.13.211 with SMTP id 202mr11994700wmn.23.1497774597854; Sun, 18 Jun 2017 01:29:57 -0700 (PDT) From: Tobias Schramm To: qemu-devel@nongnu.org Date: Sun, 18 Jun 2017 10:28:13 +0200 Message-Id: <20170618082813.8091-2-tobleminer@gmail.com> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20170618082813.8091-1-tobleminer@gmail.com> References: <20170618082813.8091-1-tobleminer@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PATCH 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: Tobias Schramm 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 --- fsdev/file-op-9p.h | 4 ++++ fsdev/qemu-fsdev-opts.c | 12 ++++++++++++ hw/9pfs/9p-local.c | 33 +++++++++++++++++++++++++++++---- hw/9pfs/9p.c | 3 +++ 4 files changed, 48 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..5c312298e8 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"); + long mask; Error *err =3D NULL; =20 if (!sec_model) { @@ -1469,6 +1472,28 @@ 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) { + mask =3D strtol(fmask, NULL, 0); + if((!mask || mask =3D=3D LONG_MIN || mask =3D=3D LONG_MAX) && errn= o) + { + 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) { + mask =3D strtol(dmask, NULL, 0); + if((!mask || mask =3D=3D LONG_MIN || mask =3D=3D LONG_MAX) && errn= o) + { + 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