From nobody Sun Nov 2 11:45:23 2025 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.zohomail.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 152731236602135.133270809526834; Fri, 25 May 2018 22:26:06 -0700 (PDT) Received: from localhost ([::1]:47804 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fMRiN-0007eB-6u for importer@patchew.org; Sat, 26 May 2018 01:26:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fMRgS-0006Db-Sg for qemu-devel@nongnu.org; Sat, 26 May 2018 01:24:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fMRgR-0004UG-EL for qemu-devel@nongnu.org; Sat, 26 May 2018 01:24:04 -0400 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]:40301) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fMRgR-0004U2-9E for qemu-devel@nongnu.org; Sat, 26 May 2018 01:24:03 -0400 Received: by mail-qt0-x242.google.com with SMTP id h2-v6so9175894qtp.7 for ; Fri, 25 May 2018 22:24:03 -0700 (PDT) Received: from localhost.localdomain (96-86-104-61-static.hfc.comcastbusiness.net. [96.86.104.61]) by smtp.gmail.com with ESMTPSA id n128-v6sm17675166qkf.42.2018.05.25.22.24.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 25 May 2018 22:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=juliacomputing-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=1Zn0ehjE2H4Zc1RnbhaPGGdekt0XYu8iGpIpleLYey0=; b=Ak3TlfNOhZJYnHS8lbrgs9w3btSo3i/8Fr7E2vIA2pdPcj6X6cst9vqcaul6TDbicV 3XdGuBHBr3kDVCidVNRgY0A7KBrfjpLjCgYXCK3S7EbWLcRJ4Yu9XcEo1hhqJ/EHNJMu lSYftvnvvHix7Njm7l0EPzn2V934l/7xlrbTqpNIwVI6HZ9C8ns7/sqol8+cFq0GH4dK 0CP+oKWchtX5LQ4HBak0CEjSGZIRoVBzwyFxfT5v4sd+wwusFvnRrU8F71IvlBwKYxVr aoMAiPdSe/Jiq5hewotfugtVfLb+MLLczzt4L5asFZVeu01DEJAAscHEPVTmF2041keZ w4Cw== 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:in-reply-to:references; bh=1Zn0ehjE2H4Zc1RnbhaPGGdekt0XYu8iGpIpleLYey0=; b=b8NIhC5VAdTgl413JbuSjkNJJoLAInsr5tf/1hRQrfL34bAdlo4X7wc1yLpkFumd8G grJ71BT7peAIGFcDiyplt+cG6Ba3lcBriSLeGKmH5wrOcuN95t6X8QkLWRWw99qefjwX YtTPSxdCqm/7/HWeUGPvUTrwPaImE8fhl/wpT4ZNLzmRabuHzuezPW2fGRjUiaFOmLw7 BL+zKLczr2pWKemICLFoppt7hIzQoOlgZRWMwLZjBLYahN1vRo70DgIEe4Mdb1H8FYJG 0Q1zPmJG+wnxsjB3RTXpt37cLerJQ/pWg2RToQY2aDaMRuf843iOhDon02I6IsKHAvXt Fv+Q== X-Gm-Message-State: ALKqPwc7m2uLXCdQ2AqvxSc9Y92mKudP0ciaiIAd/X2Ru1mU2s8udaL/ QJ4SUdmN33Mx+gbODGBlenQpM672qjQ= X-Google-Smtp-Source: ADUXVKKLGqr1eqdZaBh1L/kSUbmbV3A6olMD8cIkKJYMF0fQ4rdqFVUVETM+MMnWqQUN5Zj4tMuW9Q== X-Received: by 2002:ac8:2a2f:: with SMTP id k44-v6mr5137228qtk.180.1527312242341; Fri, 25 May 2018 22:24:02 -0700 (PDT) From: keno@juliacomputing.com To: qemu-devel@nongnu.org Date: Sat, 26 May 2018 01:23:05 -0400 Message-Id: <033ba6f2e3f0daccb31e1930a1c65cf7a18ae66c.1527310210.git.keno@alumni.harvard.edu> X-Mailer: git-send-email 2.8.1 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::242 Subject: [Qemu-devel] [PATCH 03/13] 9p: Move a couple xattr functions to 9p-util 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: Keno Fischer , Keno Fischer , 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" From: Keno Fischer These functions will need custom implementations on Darwin. Since the implementation is very similar among all of them, and 9p-util already has the _nofollow version of fgetxattrat, let's move them all there. Additionally, introduce a _follow version of fgetxattr and use it. On darwin, fgetxattr has a more general interface, so we'll need to factor it out anyway. Signed-off-by: Keno Fischer --- hw/9pfs/9p-local.c | 11 +++++++---- hw/9pfs/9p-util.c | 39 +++++++++++++++++++++++++++++++++++++++ hw/9pfs/9p-util.h | 6 ++++++ hw/9pfs/9p-xattr.c | 33 --------------------------------- 4 files changed, 52 insertions(+), 37 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 7592f8d..fd65d04 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -776,16 +776,19 @@ static int local_fstat(FsContext *fs_ctx, int fid_typ= e, mode_t tmp_mode; dev_t tmp_dev; =20 - if (fgetxattr(fd, "user.virtfs.uid", &tmp_uid, sizeof(uid_t)) > 0)= { + if (fgetxattr_follow(fd, "user.virtfs.uid", &tmp_uid, sizeof(uid_t= )) > 0) { stbuf->st_uid =3D le32_to_cpu(tmp_uid); } - if (fgetxattr(fd, "user.virtfs.gid", &tmp_gid, sizeof(gid_t)) > 0)= { + if (fgetxattr_follow(fd, "user.virtfs.gid", &tmp_gid, sizeof(gid_t= )) > 0) + { stbuf->st_gid =3D le32_to_cpu(tmp_gid); } - if (fgetxattr(fd, "user.virtfs.mode", &tmp_mode, sizeof(mode_t)) >= 0) { + if (fgetxattr_follow(fd, "user.virtfs.mode", &tmp_mode, sizeof(mod= e_t)) > 0) + { stbuf->st_mode =3D le32_to_cpu(tmp_mode); } - if (fgetxattr(fd, "user.virtfs.rdev", &tmp_dev, sizeof(dev_t)) > 0= ) { + if (fgetxattr_follow(fd, "user.virtfs.rdev", &tmp_dev, sizeof(dev_= t)) > 0) + { stbuf->st_rdev =3D le64_to_cpu(tmp_dev); } } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { diff --git a/hw/9pfs/9p-util.c b/hw/9pfs/9p-util.c index f709c27..8cf5554 100644 --- a/hw/9pfs/9p-util.c +++ b/hw/9pfs/9p-util.c @@ -24,3 +24,42 @@ ssize_t fgetxattrat_nofollow(int dirfd, const char *file= name, const char *name, g_free(proc_path); return ret; } + +ssize_t fgetxattr_follow(int fd, const char *name, + void *value, size_t size) +{ + return fgetxattr(fd, name, value, size); +} + +ssize_t flistxattrat_nofollow(int dirfd, const char *filename, + char *list, size_t size) +{ + char *proc_path =3D g_strdup_printf("/proc/self/fd/%d/%s", dirfd, file= name); + int ret; + + ret =3D llistxattr(proc_path, list, size); + g_free(proc_path); + return ret; +} + +ssize_t fremovexattrat_nofollow(int dirfd, const char *filename, + const char *name) +{ + char *proc_path =3D g_strdup_printf("/proc/self/fd/%d/%s", dirfd, file= name); + int ret; + + ret =3D lremovexattr(proc_path, name); + g_free(proc_path); + return ret; +} + +int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name, + void *value, size_t size, int flags) +{ + char *proc_path =3D g_strdup_printf("/proc/self/fd/%d/%s", dirfd, file= name); + int ret; + + ret =3D lsetxattr(proc_path, name, value, size, flags); + g_free(proc_path); + return ret; +} diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h index dc0d2e2..cb26343 100644 --- a/hw/9pfs/9p-util.h +++ b/hw/9pfs/9p-util.h @@ -58,7 +58,13 @@ static inline int openat_file(int dirfd, const char *nam= e, int flags, =20 ssize_t fgetxattrat_nofollow(int dirfd, const char *path, const char *name, void *value, size_t size); +ssize_t fgetxattr_follow(int fd, const char *name, + void *value, size_t size); int fsetxattrat_nofollow(int dirfd, const char *path, const char *name, void *value, size_t size, int flags); +ssize_t flistxattrat_nofollow(int dirfd, const char *filename, + char *list, size_t size); +ssize_t fremovexattrat_nofollow(int dirfd, const char *filename, + const char *name); =20 #endif diff --git a/hw/9pfs/9p-xattr.c b/hw/9pfs/9p-xattr.c index d05c1a1..c696d8f 100644 --- a/hw/9pfs/9p-xattr.c +++ b/hw/9pfs/9p-xattr.c @@ -60,17 +60,6 @@ ssize_t pt_listxattr(FsContext *ctx, const char *path, return name_size; } =20 -static ssize_t flistxattrat_nofollow(int dirfd, const char *filename, - char *list, size_t size) -{ - char *proc_path =3D g_strdup_printf("/proc/self/fd/%d/%s", dirfd, file= name); - int ret; - - ret =3D llistxattr(proc_path, list, size); - g_free(proc_path); - return ret; -} - /* * Get the list and pass to each layer to find out whether * to send the data or not @@ -196,17 +185,6 @@ ssize_t pt_getxattr(FsContext *ctx, const char *path, = const char *name, return local_getxattr_nofollow(ctx, path, name, value, size); } =20 -int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name, - void *value, size_t size, int flags) -{ - char *proc_path =3D g_strdup_printf("/proc/self/fd/%d/%s", dirfd, file= name); - int ret; - - ret =3D lsetxattr(proc_path, name, value, size, flags); - g_free(proc_path); - return ret; -} - ssize_t local_setxattr_nofollow(FsContext *ctx, const char *path, const char *name, void *value, size_t size, int flags) @@ -235,17 +213,6 @@ int pt_setxattr(FsContext *ctx, const char *path, cons= t char *name, void *value, return local_setxattr_nofollow(ctx, path, name, value, size, flags); } =20 -static ssize_t fremovexattrat_nofollow(int dirfd, const char *filename, - const char *name) -{ - char *proc_path =3D g_strdup_printf("/proc/self/fd/%d/%s", dirfd, file= name); - int ret; - - ret =3D lremovexattr(proc_path, name); - g_free(proc_path); - return ret; -} - ssize_t local_removexattr_nofollow(FsContext *ctx, const char *path, const char *name) { --=20 2.8.1