fstests.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Roesch <shr@fb.com>
To: <fstests@vger.kernel.org>, <kernel-team@fb.com>
Cc: <shr@fb.com>
Subject: [PATCH v5 2/2] fstress: add suport for using liburing getxattr
Date: Mon, 20 Dec 2021 10:15:40 -0800	[thread overview]
Message-ID: <20211220181540.1557109-3-shr@fb.com> (raw)
In-Reply-To: <20211220181540.1557109-1-shr@fb.com>

Liburing added support for getxattr. This change adds
support for this this in fsstress when fsstress is built
with liburing support.

Signed-off-by: Stefan Roesch <shr@fb.com>
---
 ltp/fsstress.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 59 insertions(+), 4 deletions(-)

diff --git a/ltp/fsstress.c b/ltp/fsstress.c
index bc4db73a..efd154a6 100644
--- a/ltp/fsstress.c
+++ b/ltp/fsstress.c
@@ -141,6 +141,7 @@ typedef enum {
 	OP_TRUNCATE,
 	OP_UNLINK,
 	OP_UNRESVSP,
+	OP_URING_GETXATTR,
 	OP_URING_READ,
 	OP_URING_SETXATTR,
 	OP_URING_WRITE,
@@ -152,6 +153,7 @@ typedef enum {
 typedef long long opnum_t;
 
 typedef void (*opfnc_t)(opnum_t, long);
+typedef ssize_t (*getxattr_cbk)(const char *, const char *, void *, size_t);
 typedef int (*setxattr_cbk)(const char *, const char *, const void *, size_t, int);
 
 typedef struct opdesc {
@@ -274,6 +276,7 @@ void	sync_f(opnum_t, long);
 void	truncate_f(opnum_t, long);
 void	unlink_f(opnum_t, long);
 void	unresvsp_f(opnum_t, long);
+void	uring_getxattr_f(opnum_t, long);
 void	uring_read_f(opnum_t, long);
 void	uring_setxattr_f(opnum_t, long);
 void	uring_write_f(opnum_t, long);
@@ -345,6 +348,7 @@ struct opdesc	ops[OP_LAST]	= {
 	[OP_TRUNCATE]	   	= {"truncate",		truncate_f,		2, 1 },
 	[OP_UNLINK]	   	= {"unlink",		unlink_f,		1, 1 },
 	[OP_UNRESVSP]	   	= {"unresvsp",		unresvsp_f,		1, 1 },
+	[OP_URING_GETXATTR]	= {"uring_getxattr",	uring_getxattr_f,	1, 0 },
 	[OP_URING_READ]	   	= {"uring_read",	uring_read_f,		1, 0 },
 	[OP_URING_SETXATTR]	= {"uring_setxattr",	uring_setxattr_f,	1, 1 },
 	[OP_URING_WRITE]   	= {"uring_write",	uring_write_f,		1, 1 },
@@ -3891,8 +3895,44 @@ getdents_f(opnum_t opno, long r)
 	closedir(dir);
 }
 
-void
-getfattr_f(opnum_t opno, long r)
+static ssize_t
+io_uring_getxattr(const char *path, const char *name, void *value, size_t size)
+{
+	struct io_uring_sqe *sqe;
+	struct io_uring_cqe *cqe;
+	int ret;
+
+	sqe = io_uring_get_sqe(&ring);
+	if (!sqe) {
+		printf("io_uring_get_sqe failed\n");
+		ret = -1;
+		goto out;
+	}
+
+	io_uring_prep_getxattr(sqe, name, value, path, size);
+
+	ret = io_uring_submit_and_wait(&ring, 1);
+	if (ret != 1) {
+		printf("io_uring_submit_and_wait failed, ret=%d\n", ret);
+		ret = -1;
+		goto out;
+	}
+
+	ret = io_uring_wait_cqe(&ring, &cqe);
+	if (ret < 0) {
+		printf("io_uring_wait_cqe failed, ret=%d\n", ret);
+		goto out;
+	}
+
+	ret = cqe->res;
+	io_uring_cqe_seen(&ring, cqe);
+
+out:
+	return ret;
+}
+
+static void
+getfattr_f_cbk(opnum_t opno, long r, getxattr_cbk cbk)
 {
 	fent_t	        *fep;
 	int		e;
@@ -3928,7 +3968,7 @@ getfattr_f(opnum_t opno, long r)
 		goto out;
 	}
 
-	value_len = getxattr(f.path, name, NULL, 0);
+	value_len = cbk(f.path, name, NULL, 0);
 	if (value_len < 0) {
 		if (v)
 			printf("%d/%lld: getfattr file %s name %s failed %d\n",
@@ -3950,7 +3990,8 @@ getfattr_f(opnum_t opno, long r)
 		goto out;
 	}
 
-	e = getxattr(f.path, name, value, value_len) < 0 ? errno : 0;
+	e = cbk(f.path, name, value, value_len) < 0 ? errno : 0;
+
 out_log:
 	if (v)
 		printf("%d/%lld: getfattr file %s name %s value length %d %d\n",
@@ -3960,6 +4001,20 @@ out:
 	free_pathname(&f);
 }
 
+void
+uring_getxattr_f(opnum_t opno, long r)
+{
+#ifdef URING
+	getfattr_f_cbk(opno, r, io_uring_getxattr);
+#endif
+}
+
+void
+getfattr_f(opnum_t opno, long r)
+{
+	getfattr_f_cbk(opno, r, getxattr);
+}
+
 void
 link_f(opnum_t opno, long r)
 {
-- 
2.30.2


  parent reply	other threads:[~2021-12-20 18:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-20 18:15 [PATCH v5 0/2] Add support for using liburing xattr Stefan Roesch
2021-12-20 18:15 ` [PATCH v5 1/2] fstress: add suport for using liburing setxattr Stefan Roesch
2021-12-20 18:15 ` Stefan Roesch [this message]
2021-12-25 13:40 ` [PATCH v5 0/2] Add support for using liburing xattr Eryu Guan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211220181540.1557109-3-shr@fb.com \
    --to=shr@fb.com \
    --cc=fstests@vger.kernel.org \
    --cc=kernel-team@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).