Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Mar 2013 18:37:51 -0700
From:      mdf@FreeBSD.org
To:        freebsd-current@freebsd.org, freebsd-fs@freebsd.org
Subject:   [RFC] use a shared lock for VOP_GETEXTATTR
Message-ID:  <CAMBSHm9VgD9Pcmiap3Cy1eW8GD9k06q%2BsCzaSJ%2B_wyA6ZFioTA@mail.gmail.com>
In-Reply-To: <CAMBSHm8Akz2-tUhjYm9%2BH3YTN31N8=OhGHX1ZpdV4-VixFQm%2BQ@mail.gmail.com>
References:  <CAMBSHm8Akz2-tUhjYm9%2BH3YTN31N8=OhGHX1ZpdV4-VixFQm%2BQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
VOP_GETEXTATTR is currently called with an exclusive lock, which seems
like overkill for what is essentially a read operation.  I had a look
over the various in-tree filesystems and it didn't look like any of
them will have a problem if a shared-mode lock is used for
vop_getextattr.

Does anyone know otherwise?  Is someone using extended attributes
regularly who can test this?

[sorry if this is a duplicate; I first sent from my non-FreeBSD mail]

Thanks,
matthew

[-- Attachment #2 --]
From aa6d6c716bd19ce32e3b908727fbda65d345b7ab Mon Sep 17 00:00:00 2001
From: Matthew Fleming <mdf@FreeBSD.org>
Date: Wed, 27 Mar 2013 18:23:17 -0700
Subject: [PATCH] Use a shared lock for VOP_GETEXTATTR, as it is a read-like operation.

MFC after:	1 week
---
 sys/kern/vfs_extattr.c |    2 +-
 sys/kern/vfs_vnops.c   |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/kern/vfs_extattr.c b/sys/kern/vfs_extattr.c
index 85fc839..700a70c 100644
--- a/sys/kern/vfs_extattr.c
+++ b/sys/kern/vfs_extattr.c
@@ -321,17 +321,17 @@ extattr_get_vp(struct vnode *vp, int attrnamespace, const char *attrname,
     void *data, size_t nbytes, struct thread *td)
 {
 	struct uio auio, *auiop;
 	struct iovec aiov;
 	ssize_t cnt;
 	size_t size, *sizep;
 	int error;
 
-	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+	vn_lock(vp, LK_SHARED | LK_RETRY);
 
 	/*
 	 * Slightly unusual semantics: if the user provides a NULL data
 	 * pointer, they don't want to receive the data, just the maximum
 	 * read length.
 	 */
 	auiop = NULL;
 	sizep = NULL;
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index c8f832f..6849730 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -1753,17 +1753,17 @@ vn_extattr_get(struct vnode *vp, int ioflg, int attrnamespace,
 	auio.uio_iovcnt = 1;
 	auio.uio_rw = UIO_READ;
 	auio.uio_segflg = UIO_SYSSPACE;
 	auio.uio_td = td;
 	auio.uio_offset = 0;
 	auio.uio_resid = *buflen;
 
 	if ((ioflg & IO_NODELOCKED) == 0)
-		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+		vn_lock(vp, LK_SHARED | LK_RETRY);
 
 	ASSERT_VOP_LOCKED(vp, "IO_NODELOCKED with no vp lock held");
 
 	/* authorize attribute retrieval as kernel */
 	error = VOP_GETEXTATTR(vp, attrnamespace, attrname, &auio, NULL, NULL,
 	    td);
 
 	if ((ioflg & IO_NODELOCKED) == 0)
-- 
1.7.3.2


Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAMBSHm9VgD9Pcmiap3Cy1eW8GD9k06q%2BsCzaSJ%2B_wyA6ZFioTA>