From patchwork Thu Mar 28 18:53:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 10875701 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02AF0922 for ; Thu, 28 Mar 2019 18:54:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E459928770 for ; Thu, 28 Mar 2019 18:54:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D89D928827; Thu, 28 Mar 2019 18:54:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D9E228770 for ; Thu, 28 Mar 2019 18:53:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726266AbfC1Sx7 (ORCPT ); Thu, 28 Mar 2019 14:53:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:44960 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbfC1Sx7 (ORCPT ); Thu, 28 Mar 2019 14:53:59 -0400 Received: from localhost.localdomain (bl8-197-74.dsl.telepac.pt [85.241.197.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D534B20823; Thu, 28 Mar 2019 18:53:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553799237; bh=lPHlZwUaNNGQHi729o8QX8ff7ngcdGAlRQW2f0O15ts=; h=From:To:Cc:Subject:Date:From; b=Vlha13xWtWL/AgdYSdTaLFsaQd3dDimmCQwvk9/OTah+NCrinBzsoqO1RuJiOPDAM O7XjoH6mMzK4JEZ+M3pdhZVLbrw5w8Wnq+Uj5V4w2cqdgrgzQVJLPaCUemSBJ67138 ItaJBYNEdwoJQm+WD3lFrRQ3T8nNWp/eSZ3t16Y0= From: fdmanana@kernel.org To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Filipe Manana Subject: [PATCH 1/7] fsstress: rename setxattr operation to chproj Date: Thu, 28 Mar 2019 18:53:52 +0000 Message-Id: <20190328185352.28829-1-fdmanana@kernel.org> X-Mailer: git-send-email 2.11.0 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Filipe Manana The existing setxattr operation is used to change the project identifier attribute associated with an inode, and not about setting a xattr (the name and value pair) for a file/directory, which is confusing. So rename the operation to chproj, which is more descriptive about what it does and avoids any confusion. Fsstress currently has no operations for setting and getting xattrs of a file (for any namespace), and this patch is a preparation for adding such operations in a subsequent patch. This operation actually used to be named chproj until the following commit: commit 6449a993f2dfb3faaaa44e29d2f7d1bb7c5db9ba Author: Nathan Scott Date: Mon Dec 5 21:41:47 2005 +0000 Switch to always using get/setxattr rather than a separate projid call on IRIX. Merge of master-melb:xfs-cmds:24692a by kenmcd. Which does not explain the rationale for the renaming at all. Signed-off-by: Filipe Manana --- ltp/fsstress.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ltp/fsstress.c b/ltp/fsstress.c index 2223fd7d..cc4f520e 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -55,6 +55,7 @@ typedef enum { OP_BULKSTAT, OP_BULKSTAT1, OP_CHOWN, + OP_CHPROJ, OP_CLONERANGE, OP_COPYRANGE, OP_CREAT, @@ -84,7 +85,6 @@ typedef enum { OP_RESVSP, OP_RMDIR, OP_SETATTR, - OP_SETXATTR, OP_SPLICE, OP_STAT, OP_SYMLINK, @@ -165,6 +165,7 @@ void awrite_f(int, long); void bulkstat_f(int, long); void bulkstat1_f(int, long); void chown_f(int, long); +void chproj_f(int, long); void clonerange_f(int, long); void copyrange_f(int, long); void creat_f(int, long); @@ -194,7 +195,6 @@ void rename_f(int, long); void resvsp_f(int, long); void rmdir_f(int, long); void setattr_f(int, long); -void setxattr_f(int, long); void splice_f(int, long); void stat_f(int, long); void symlink_f(int, long); @@ -216,6 +216,7 @@ opdesc_t ops[] = { { OP_BULKSTAT, "bulkstat", bulkstat_f, 1, 0 }, { OP_BULKSTAT1, "bulkstat1", bulkstat1_f, 1, 0 }, { OP_CHOWN, "chown", chown_f, 3, 1 }, + { OP_CHPROJ, "chproj", chproj_f, 1, 1 }, { OP_CLONERANGE, "clonerange", clonerange_f, 4, 1 }, { OP_COPYRANGE, "copyrange", copyrange_f, 4, 1 }, { OP_CREAT, "creat", creat_f, 4, 1 }, @@ -245,7 +246,6 @@ opdesc_t ops[] = { { OP_RESVSP, "resvsp", resvsp_f, 1, 1 }, { OP_RMDIR, "rmdir", rmdir_f, 1, 1 }, { OP_SETATTR, "setattr", setattr_f, 0, 1 }, - { OP_SETXATTR, "setxattr", setxattr_f, 1, 1 }, { OP_SPLICE, "splice", splice_f, 1, 1 }, { OP_STAT, "stat", stat_f, 1, 0 }, { OP_SYMLINK, "symlink", symlink_f, 2, 1 }, @@ -2732,7 +2732,7 @@ out_fdr: } void -setxattr_f(int opno, long r) +chproj_f(int opno, long r) { #ifdef XFS_XFLAG_EXTSIZE struct fsxattr fsx; @@ -2761,7 +2761,7 @@ setxattr_f(int opno, long r) e = xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &fsx); } if (v) - printf("%d/%d: setxattr %s %u %d\n", procid, opno, f.path, p, e); + printf("%d/%d: chproj %s %u %d\n", procid, opno, f.path, p, e); free_pathname(&f); close(fd); #endif From patchwork Thu Mar 28 18:54:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 10875703 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C63414DE for ; Thu, 28 Mar 2019 18:54:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7294128770 for ; Thu, 28 Mar 2019 18:54:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64DCD288D0; Thu, 28 Mar 2019 18:54:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 960E528770 for ; Thu, 28 Mar 2019 18:54:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726381AbfC1SyL (ORCPT ); Thu, 28 Mar 2019 14:54:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:45116 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbfC1SyL (ORCPT ); Thu, 28 Mar 2019 14:54:11 -0400 Received: from localhost.localdomain (bl8-197-74.dsl.telepac.pt [85.241.197.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D71D720823; Thu, 28 Mar 2019 18:54:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553799249; bh=M+3honXGH6YFbXRUbAZmEjgeNo6sdzUonaVrBVGm/3k=; h=From:To:Cc:Subject:Date:From; b=IvERS/GMZIf1Gv2WuRitV4qwEbggJFY0k0YgHkTR9IfLdggOpM2o/Mt+72I8Rgq+C xfLo1vcGlbReIa1mo+cbtonWjR7PjwQAl9SldhHqy+KM13eOOC7DrEoteugJ6qPmfK /hlP69VTdg/I/vzGIKmPsMC6KCLk/HhhMeTSqmRA= From: fdmanana@kernel.org To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Filipe Manana Subject: [PATCH 2/7] fsstress: add operation for setting xattrs on files and directories Date: Thu, 28 Mar 2019 18:54:04 +0000 Message-Id: <20190328185404.28879-1-fdmanana@kernel.org> X-Mailer: git-send-email 2.11.0 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Filipe Manana Currently fsstress does not exercise creating, reading or deleting xattrs on files or directories. This change adds support for setting xattrs on files and directories, using only the xattr user namespace (the other namespaces are not general purpose and are used for security, capabilities, ACLs, etc). This adds a counter for each file entry structure that keeps track of the number of xattrs set for the file entry, and each new xattr has a name that includes the counter's value (example: "user.x4"). Values for the xattrs have at most 100 bytes, which is much more than the maximum size supported for all major filesystems. Signed-off-by: Filipe Manana --- ltp/fsstress.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 141 insertions(+), 9 deletions(-) diff --git a/ltp/fsstress.c b/ltp/fsstress.c index cc4f520e..03e40eb6 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -27,6 +27,7 @@ io_context_t io_ctx; #endif #include +#include #ifndef FS_IOC_GETFLAGS #define FS_IOC_GETFLAGS _IOR('f', 1, long) @@ -85,6 +86,7 @@ typedef enum { OP_RESVSP, OP_RMDIR, OP_SETATTR, + OP_SETXATTR, OP_SPLICE, OP_STAT, OP_SYMLINK, @@ -110,6 +112,7 @@ typedef struct opdesc { typedef struct fent { int id; int parent; + int xattr_counter; } fent_t; typedef struct flist { @@ -195,6 +198,7 @@ void rename_f(int, long); void resvsp_f(int, long); void rmdir_f(int, long); void setattr_f(int, long); +void setxattr_f(int, long); void splice_f(int, long); void stat_f(int, long); void symlink_f(int, long); @@ -246,6 +250,7 @@ opdesc_t ops[] = { { OP_RESVSP, "resvsp", resvsp_f, 1, 1 }, { OP_RMDIR, "rmdir", rmdir_f, 1, 1 }, { OP_SETATTR, "setattr", setattr_f, 0, 1 }, + { OP_SETXATTR, "setxattr", setxattr_f, 4, 1 }, { OP_SPLICE, "splice", splice_f, 1, 1 }, { OP_STAT, "stat", stat_f, 1, 0 }, { OP_SYMLINK, "symlink", symlink_f, 2, 1 }, @@ -296,7 +301,7 @@ char *execute_cmd = NULL; int execute_freq = 1; struct print_string flag_str = {0}; -void add_to_flist(int, int, int); +void add_to_flist(int, int, int, int); void append_pathname(pathname_t *, char *); int attr_list_path(pathname_t *, char *, const int, int, attrlist_cursor_t *); int attr_remove_path(pathname_t *, const char *, int); @@ -715,7 +720,7 @@ translate_flags(int flags, const char *delim, } void -add_to_flist(int ft, int id, int parent) +add_to_flist(int ft, int id, int parent, int xattr_counter) { fent_t *fep; flist_t *ftp; @@ -728,6 +733,7 @@ add_to_flist(int ft, int id, int parent) fep = &ftp->fents[ftp->nfiles++]; fep->id = id; fep->parent = parent; + fep->xattr_counter = xattr_counter; } void @@ -3000,7 +3006,7 @@ creat_f(int opno, long r) if (xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &a) < 0) e1 = errno; } - add_to_flist(type, id, parid); + add_to_flist(type, id, parid, 0); close(fd); } if (v) { @@ -3527,9 +3533,10 @@ link_f(int opno, long r) int parid; int v; int v1; + fent_t *fep_source; init_pathname(&f); - if (!get_fname(FT_NOTDIR, r, &f, &flp, NULL, &v1)) { + if (!get_fname(FT_NOTDIR, r, &f, &flp, &fep_source, &v1)) { if (v1) printf("%d/%d: link - no file\n", procid, opno); free_pathname(&f); @@ -3556,7 +3563,7 @@ link_f(int opno, long r) e = link_path(&f, &l) < 0 ? errno : 0; check_cwd(); if (e == 0) - add_to_flist(flp - flist, id, parid); + add_to_flist(flp - flist, id, parid, fep_source->xattr_counter); if (v) { printf("%d/%d: link %s %s %d\n", procid, opno, f.path, l.path, e); @@ -3596,7 +3603,7 @@ mkdir_f(int opno, long r) e = mkdir_path(&f, 0777) < 0 ? errno : 0; check_cwd(); if (e == 0) - add_to_flist(FT_DIR, id, parid); + add_to_flist(FT_DIR, id, parid, 0); if (v) { printf("%d/%d: mkdir %s %d\n", procid, opno, f.path, e); printf("%d/%d: mkdir add id=%d,parent=%d\n", procid, opno, id, parid); @@ -3634,7 +3641,7 @@ mknod_f(int opno, long r) e = mknod_path(&f, S_IFCHR|0444, 0) < 0 ? errno : 0; check_cwd(); if (e == 0) - add_to_flist(FT_DEV, id, parid); + add_to_flist(FT_DEV, id, parid, 0); if (v) { printf("%d/%d: mknod %s %d\n", procid, opno, f.path, e); printf("%d/%d: mknod add id=%d,parent=%d\n", procid, opno, id, parid); @@ -4010,12 +4017,14 @@ rename_f(int opno, long r) e = rename_path(&f, &newf) < 0 ? errno : 0; check_cwd(); if (e == 0) { + int xattr_counter = fep->xattr_counter; + if (flp - flist == FT_DIR) { oldid = fep->id; fix_parent(oldid, id); } del_from_flist(flp - flist, fep - flp->fents); - add_to_flist(flp - flist, id, parid); + add_to_flist(flp - flist, id, parid, xattr_counter); } if (v) { printf("%d/%d: rename %s to %s %d\n", procid, opno, f.path, @@ -4137,6 +4146,129 @@ setattr_f(int opno, long r) close(fd); } +char *gen_random_string(int len) +{ + static const char charset[] = "0123456789" + "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + int i; + char *s; + + if (len == 0) + return NULL; + + s = malloc(len); + if (!s) + return NULL; + + for (i = 0; i < len; i++) + s[i] = charset[random() % (sizeof(charset))]; + + return s; +} + +char *xattr_flag_to_string(int flag) +{ + if (flag == XATTR_CREATE) + return "create"; + if (flag == XATTR_REPLACE) + return "replace"; + return "none"; +} + +void +setxattr_f(int opno, long r) +{ + int fd; + int e; + pathname_t f; + fent_t *fep; + int v; + int value_len; + char name[18]; + char *value; + int flag = 0; + int xattr_num; + DIR *dir = NULL; + + init_pathname(&f); + if (!get_fname(FT_REGFILE | FT_DIRm, r, &f, NULL, &fep, &v)) { + if (v) + printf("%d/%d: setxattr - no filename\n", procid, opno); + free_pathname(&f); + return; + } + fd = open_path(&f, O_WRONLY); + if (fd < 0 && errno == EISDIR) { + dir = opendir_path(&f); + if (dir) + fd = dirfd(dir); + } + e = fd < 0 ? errno : 0; + if (fd < 0) { + if (v) + printf("%d/%d: setxattr - open %s failed %d\n", + procid, opno, f.path, e); + free_pathname(&f); + if (dir) + closedir(dir); + return; + } + check_cwd(); + + if ((fep->xattr_counter > 0) && (random() % 2)) { + /* + * Use an existing xattr name for replacing its value or + * create again a xattr that was previously deleted. + */ + xattr_num = (random() % fep->xattr_counter) + 1; + if (random() % 2) + flag = XATTR_REPLACE; + } else { + /* Use a new xattr name. */ + fep->xattr_counter++; + xattr_num = fep->xattr_counter; + /* + * Don't always use the create flag because even if our xattr + * counter is 0, we may still have xattrs associated to this + * file - this happens when xattrs are added to a file through + * one of its other hard links. + */ + if (random() % 2) + flag = XATTR_CREATE; + } + + /* + * The maximum supported value size depends on the filesystem + * implementation, but 100 bytes is a safe value for most filesystems + * at least. + */ + value_len = random() % 101; + + memcpy(name, "user.x", 6); + sprintf(name + 6, "%d", xattr_num); + value = gen_random_string(value_len); + if (!value && value_len > 0) { + if (v) + printf("%d/%d: setxattr - file %s failed to allocate value with %d bytes\n", + procid, opno, f.path, value_len); + goto out; + } + + e = fsetxattr(fd, name, value, value_len, flag) < 0 ? errno : 0; + if (v) + printf("%d/%d: setxattr file %s name %s flag %s value length %d: %d\n", + procid, opno, f.path, name, xattr_flag_to_string(flag), + value_len, e); +out: + free(value); + free_pathname(&f); + if (dir) + closedir(dir); + else + close(fd); +} + void stat_f(int opno, long r) { @@ -4199,7 +4331,7 @@ symlink_f(int opno, long r) e = symlink_path(val, &f) < 0 ? errno : 0; check_cwd(); if (e == 0) - add_to_flist(FT_SYM, id, parid); + add_to_flist(FT_SYM, id, parid, 0); free(val); if (v) { printf("%d/%d: symlink %s %d\n", procid, opno, f.path, e); From patchwork Thu Mar 28 18:54:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 10875707 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 58CB2922 for ; Thu, 28 Mar 2019 18:54:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4087D28770 for ; Thu, 28 Mar 2019 18:54:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34796288D0; Thu, 28 Mar 2019 18:54:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C06E728770 for ; Thu, 28 Mar 2019 18:54:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726298AbfC1SyX (ORCPT ); Thu, 28 Mar 2019 14:54:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:45220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbfC1SyX (ORCPT ); Thu, 28 Mar 2019 14:54:23 -0400 Received: from localhost.localdomain (bl8-197-74.dsl.telepac.pt [85.241.197.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6769B2173C; Thu, 28 Mar 2019 18:54:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553799262; bh=XVlUOljJ0Sear8C63j/MoeHcJeviCl/ee9EhVYxXi+s=; h=From:To:Cc:Subject:Date:From; b=duY+AKs37w51WZ7o4pA6EJcbrjftoBbILd/Fm/y6zRuu8IAyMzq1LLnMcf4ZeZgpJ VAHlFpeQThUH/xWeQYqHElAYyAEkvI1osddFU59CrXtyLrpzDTltFY3BakAU1YOuZQ 0xmXgMLUBdK6BF+kpgJdPAhidZdkRGccH7jFXC34= From: fdmanana@kernel.org To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Filipe Manana Subject: [PATCH 3/7] fsstress: add operation for reading xattrs from files and directories Date: Thu, 28 Mar 2019 18:54:16 +0000 Message-Id: <20190328185416.28930-1-fdmanana@kernel.org> X-Mailer: git-send-email 2.11.0 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Filipe Manana The previous patch added support for an operation to set xattrs on regular files and directories, this patch just adds one operation to read (get) them. Signed-off-by: Filipe Manana --- ltp/fsstress.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/ltp/fsstress.c b/ltp/fsstress.c index 03e40eb6..d7ea1da0 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -70,6 +70,7 @@ typedef enum { OP_FSYNC, OP_GETATTR, OP_GETDENTS, + OP_GETXATTR, OP_LINK, OP_MKDIR, OP_MKNOD, @@ -182,6 +183,7 @@ void freesp_f(int, long); void fsync_f(int, long); void getattr_f(int, long); void getdents_f(int, long); +void getxattr_f(int, long); void link_f(int, long); void mkdir_f(int, long); void mknod_f(int, long); @@ -234,6 +236,7 @@ opdesc_t ops[] = { { OP_FSYNC, "fsync", fsync_f, 1, 1 }, { OP_GETATTR, "getattr", getattr_f, 1, 0 }, { OP_GETDENTS, "getdents", getdents_f, 1, 0 }, + { OP_GETXATTR, "getxattr", getxattr_f, 2, 0 }, { OP_LINK, "link", link_f, 1, 1 }, { OP_MKDIR, "mkdir", mkdir_f, 2, 1 }, { OP_MKNOD, "mknod", mknod_f, 2, 1 }, @@ -3522,6 +3525,87 @@ getdents_f(int opno, long r) } void +getxattr_f(int opno, long r) +{ + int fd; + fent_t *fep; + int e; + pathname_t f; + int v; + char name[18]; + char *value = NULL; + int value_len; + int xattr_num; + DIR *dir = NULL; + + init_pathname(&f); + if (!get_fname(FT_REGFILE | FT_DIRm, r, &f, NULL, &fep, &v)) { + if (v) + printf("%d/%d: getxattr - no filename\n", procid, opno); + free_pathname(&f); + return; + } + fd = open_path(&f, O_RDONLY); + if (fd < 0 && errno == EISDIR) { + dir = opendir_path(&f); + if (dir) + fd = dirfd(dir); + } + e = fd < 0 ? errno : 0; + if (fd < 0) { + if (v) + printf("%d/%d: getxattr - open %s failed %d\n", + procid, opno, f.path, e); + free_pathname(&f); + if (dir) + closedir(dir); + return; + } + check_cwd(); + + /* + * If the file/dir has xattrs, pick one randomly, otherwise attempt + * to read a xattr that doesn't exist (fgetxattr should fail with + * errno set to ENOATTR (61) in this case). + */ + if (fep->xattr_counter > 0) + xattr_num = (random() % fep->xattr_counter) + 1; + else + xattr_num = 0; + + memcpy(name, "user.x", 6); + sprintf(name + 6, "%d", xattr_num); + + value_len = fgetxattr(fd, name, NULL, 0); + if (value_len < 0) { + if (v) + printf("%d/%d: getxattr file %s failed %d\n", + procid, opno, f.path, errno); + goto out; + } + + value = malloc(value_len); + if (!value) { + if (v) + printf("%d/%d: getxattr file %s failed to allocate buffer with %d bytes\n", + procid, opno, f.path, value_len); + goto out; + } + + e = fgetxattr(fd, name, value, value_len) < 0 ? errno : 0; + if (v) + printf("%d/%d: getxattr file %s name %s value length %d %d\n", + procid, opno, f.path, name, value_len, e); +out: + free(value); + free_pathname(&f); + if (dir) + closedir(dir); + else + close(fd); +} + +void link_f(int opno, long r) { int e; From patchwork Thu Mar 28 18:54:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 10875711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5C84114DE for ; Thu, 28 Mar 2019 18:54:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45108288F3 for ; Thu, 28 Mar 2019 18:54:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 340B328A50; Thu, 28 Mar 2019 18:54:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8D44288F3 for ; Thu, 28 Mar 2019 18:54:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726165AbfC1Syg (ORCPT ); Thu, 28 Mar 2019 14:54:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:45332 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbfC1Syg (ORCPT ); Thu, 28 Mar 2019 14:54:36 -0400 Received: from localhost.localdomain (bl8-197-74.dsl.telepac.pt [85.241.197.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9D84C21773; Thu, 28 Mar 2019 18:54:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553799275; bh=FRJktOvIrTMhKmBf6eJAomEtvNvka/KlRKHgLXr2PMI=; h=From:To:Cc:Subject:Date:From; b=qRiOm+MLPKLzYndG/CdgfVHYOL5s7FcI92ayn0XdfYk27Ec8hEKHY2FGoOaUwsL1T 69I/DVmgE7VLWVyAwxSLe0/jjOkwh1lmheUFPlLJ+2CQ56Ap0NXJBXH8yHJpnvIWtd ApL9AlyUPtFyoX/57N1CghIWwHSUzDP+g6ekSZ0Q= From: fdmanana@kernel.org To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Filipe Manana Subject: [PATCH 4/7] fsstress: add operation for removing xattrs from files and directories Date: Thu, 28 Mar 2019 18:54:30 +0000 Message-Id: <20190328185430.28980-1-fdmanana@kernel.org> X-Mailer: git-send-email 2.11.0 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Filipe Manana The previous patches added support for operations to set and get xattrs on regular files and directories, this patch just adds one operation to remove xattrs on files and directories. Signed-off-by: Filipe Manana --- ltp/fsstress.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/ltp/fsstress.c b/ltp/fsstress.c index d7ea1da0..ffe78ef7 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -83,6 +83,7 @@ typedef enum { OP_READ, OP_READLINK, OP_READV, + OP_REMOVEXATTR, OP_RENAME, OP_RESVSP, OP_RMDIR, @@ -196,6 +197,7 @@ void insert_f(int, long); void read_f(int, long); void readlink_f(int, long); void readv_f(int, long); +void removexattr_f(int, long); void rename_f(int, long); void resvsp_f(int, long); void rmdir_f(int, long); @@ -249,6 +251,7 @@ opdesc_t ops[] = { { OP_READ, "read", read_f, 1, 0 }, { OP_READLINK, "readlink", readlink_f, 1, 0 }, { OP_READV, "readv", readv_f, 1, 0 }, + { OP_REMOVEXATTR, "removexattr", removexattr_f, 2, 1 }, { OP_RENAME, "rename", rename_f, 2, 1 }, { OP_RESVSP, "resvsp", resvsp_f, 1, 1 }, { OP_RMDIR, "rmdir", rmdir_f, 1, 1 }, @@ -4054,6 +4057,67 @@ readv_f(int opno, long r) } void +removexattr_f(int opno, long r) +{ + int fd; + fent_t *fep; + int e; + pathname_t f; + int v; + char name[18]; + int xattr_num; + DIR *dir = NULL; + + init_pathname(&f); + if (!get_fname(FT_REGFILE | FT_DIRm, r, &f, NULL, &fep, &v)) { + if (v) + printf("%d/%d: removexattr - no filename\n", procid, opno); + free_pathname(&f); + return; + } + fd = open_path(&f, O_WRONLY); + if (fd < 0 && errno == EISDIR) { + dir = opendir_path(&f); + if (dir) + fd = dirfd(dir); + } + e = fd < 0 ? errno : 0; + if (fd < 0) { + if (v) + printf("%d/%d: removexattr - open %s failed %d\n", + procid, opno, f.path, e); + free_pathname(&f); + if (dir) + closedir(dir); + return; + } + check_cwd(); + + /* + * If the file/dir has xattrs, pick one randomly, otherwise attempt to + * remove a xattr that doesn't exist (fremovexattr should fail with + * errno set to ENOATTR (61) in this case). + */ + if (fep->xattr_counter > 0) + xattr_num = (random() % fep->xattr_counter) + 1; + else + xattr_num = 0; + + memcpy(name, "user.x", 6); + sprintf(name + 6, "%d", xattr_num); + + e = fremovexattr(fd, name) < 0 ? errno : 0; + if (v) + printf("%d/%d: removexattr file %s name %s %d\n", + procid, opno, f.path, name, e); + free_pathname(&f); + if (dir) + closedir(dir); + else + close(fd); +} + +void rename_f(int opno, long r) { fent_t *dfep; From patchwork Thu Mar 28 18:54:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 10875717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 87CB714DE for ; Thu, 28 Mar 2019 18:55:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75F77287AE for ; Thu, 28 Mar 2019 18:55:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A3CD28D24; Thu, 28 Mar 2019 18:55:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2070428D4B for ; Thu, 28 Mar 2019 18:55:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726164AbfC1SzD (ORCPT ); Thu, 28 Mar 2019 14:55:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:45422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbfC1SzD (ORCPT ); Thu, 28 Mar 2019 14:55:03 -0400 Received: from localhost.localdomain (bl8-197-74.dsl.telepac.pt [85.241.197.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E8A3E2173C; Thu, 28 Mar 2019 18:55:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553799302; bh=bNDzHfgV44T11IZFAURJobvn0KCy+ewH3JKQdg8NzT8=; h=From:To:Cc:Subject:Date:From; b=c1JU9qqtS6i2g3Q9CzRqvVS9iQsXwc5GO+sD95+FLl9PU6b6iHba87ypdHQSegdYx 4bqEfClOhU2GXTAFfFWZVQhGxuJm+PPQHt7GN77QVEnw2HiQOX6lABOjfMUofCi2Il al4QSQHJsgBipZDsy1zCBZ8QsQEIJ80YP6MFDGiw= From: fdmanana@kernel.org To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Filipe Manana Subject: [PATCH 5/7] fsstress: allow afsync on directories too Date: Thu, 28 Mar 2019 18:54:58 +0000 Message-Id: <20190328185458.29033-1-fdmanana@kernel.org> X-Mailer: git-send-email 2.11.0 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Filipe Manana Currently the afsync function can only be performed against regular files. Allow it to operate on directories too, to increase test coverage and allow for chances of finding bugs in the filesystem implementation of fsync against directories. Signed-off-by: Filipe Manana --- ltp/fsstress.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/ltp/fsstress.c b/ltp/fsstress.c index ffe78ef7..0fb9e399 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -1767,15 +1767,21 @@ afsync_f(int opno, long r) struct iocb iocb; struct iocb *iocbs[] = { &iocb }; struct io_event event; + DIR *dir = NULL; init_pathname(&f); - if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) { + if (!get_fname(FT_REGFILE | FT_DIRm, r, &f, NULL, NULL, &v)) { if (v) printf("%d/%d: afsync - no filename\n", procid, opno); free_pathname(&f); return; } fd = open_path(&f, O_WRONLY | O_DIRECT); + if (fd < 0 && errno == EISDIR) { + dir = opendir_path(&f); + if (dir) + fd = dirfd(dir); + } e = fd < 0 ? errno : 0; check_cwd(); if (fd < 0) { @@ -1783,6 +1789,8 @@ afsync_f(int opno, long r) printf("%d/%d: afsync - open %s failed %d\n", procid, opno, f.path, e); free_pathname(&f); + if (dir) + closedir(dir); return; } @@ -1791,24 +1799,24 @@ afsync_f(int opno, long r) if (v) printf("%d/%d: afsync - io_submit %s %d\n", procid, opno, f.path, e); - free_pathname(&f); - close(fd); - return; + goto out; } if ((e = io_getevents(io_ctx, 1, 1, &event, NULL)) != 1) { if (v) printf("%d/%d: afsync - io_getevents failed %d\n", procid, opno, e); - free_pathname(&f); - close(fd); - return; + goto out; } e = event.res2; if (v) printf("%d/%d: afsync %s %d\n", procid, opno, f.path, e); +out: free_pathname(&f); - close(fd); + if (dir) + closedir(dir); + else + close(fd); #endif } From patchwork Thu Mar 28 18:55:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 10875719 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF90114DE for ; Thu, 28 Mar 2019 18:55:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9822328D37 for ; Thu, 28 Mar 2019 18:55:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CA5328D6E; Thu, 28 Mar 2019 18:55:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4251A28D37 for ; Thu, 28 Mar 2019 18:55:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726047AbfC1SzP (ORCPT ); Thu, 28 Mar 2019 14:55:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:45504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbfC1SzO (ORCPT ); Thu, 28 Mar 2019 14:55:14 -0400 Received: from localhost.localdomain (bl8-197-74.dsl.telepac.pt [85.241.197.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 66C3C2173C; Thu, 28 Mar 2019 18:55:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553799314; bh=3r53Oh8MY2VrMULjE/3iC4Kzo8dj+hEo7jO01Cvc3jU=; h=From:To:Cc:Subject:Date:From; b=h/ocv+vQeH/PiLQ0Jx0rd/IXS1Q100F3/gMmVoafkDatN/ZhMYW6LjrJUHLxUSDGC BYy8A5SqHienbQGzhyEw8CgS8iAlaHH7noeEpGe2cl01iB6Q92xLpQAbAiykx12Tga jepRHf3zm58gfGKX6X2zfrJSvEbvNcJ2Epr1CZTA= From: fdmanana@kernel.org To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Filipe Manana Subject: [PATCH 6/7] fsstress: allow fsync on directories too Date: Thu, 28 Mar 2019 18:55:09 +0000 Message-Id: <20190328185509.29086-1-fdmanana@kernel.org> X-Mailer: git-send-email 2.11.0 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Filipe Manana Currently the fsync function can only be performed against regular files. Allow it to operate on directories too, to increase test coverage and allow for chances of finding bugs in a filesystem's implementation of fsync against directories. Signed-off-by: Filipe Manana --- ltp/fsstress.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ltp/fsstress.c b/ltp/fsstress.c index 0fb9e399..bd058c04 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -3460,15 +3460,21 @@ fsync_f(int opno, long r) pathname_t f; int fd; int v; + DIR *dir = NULL; init_pathname(&f); - if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) { + if (!get_fname(FT_REGFILE | FT_DIRm, r, &f, NULL, NULL, &v)) { if (v) printf("%d/%d: fsync - no filename\n", procid, opno); free_pathname(&f); return; } fd = open_path(&f, O_WRONLY); + if (fd < 0 && errno == EISDIR) { + dir = opendir_path(&f); + if (dir) + fd = dirfd(dir); + } e = fd < 0 ? errno : 0; check_cwd(); if (fd < 0) { @@ -3476,13 +3482,18 @@ fsync_f(int opno, long r) printf("%d/%d: fsync - open %s failed %d\n", procid, opno, f.path, e); free_pathname(&f); + if (dir) + closedir(dir); return; } e = fsync(fd) < 0 ? errno : 0; if (v) printf("%d/%d: fsync %s %d\n", procid, opno, f.path, e); free_pathname(&f); - close(fd); + if (dir) + closedir(dir); + else + close(fd); } void From patchwork Thu Mar 28 18:55:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 10875723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F74B922 for ; Thu, 28 Mar 2019 18:55:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7484128D24 for ; Thu, 28 Mar 2019 18:55:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63B1F28D8A; Thu, 28 Mar 2019 18:55:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C821B28D24 for ; Thu, 28 Mar 2019 18:55:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726290AbfC1Sz0 (ORCPT ); Thu, 28 Mar 2019 14:55:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:45560 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726267AbfC1Sz0 (ORCPT ); Thu, 28 Mar 2019 14:55:26 -0400 Received: from localhost.localdomain (bl8-197-74.dsl.telepac.pt [85.241.197.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 233A22173C; Thu, 28 Mar 2019 18:55:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553799325; bh=8uROn+88m0/a5WipLGXYVgUK9IfhRM5t5+x1yds8tXc=; h=From:To:Cc:Subject:Date:From; b=h3KH/ZhsFgvd0ZoSJmECxGSNqF3GS4KdGqsl3PvMvmhnnp+hxksVx3kCn5gMsjIyt r6op8JNCpWw42SfBHmtdT8+SK0tAbwJPnOaX0cUehQgV/eRtX+OHN/sG5LseS8KZBz KFu2b4M5e05IM7rEKS7IVA1lPnOVtZJyRMiMFT80= From: fdmanana@kernel.org To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Filipe Manana Subject: [PATCH 7/7] fssum: add support for checking xattrs Date: Thu, 28 Mar 2019 18:55:20 +0000 Message-Id: <20190328185520.29140-1-fdmanana@kernel.org> X-Mailer: git-send-email 2.11.0 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Filipe Manana Currently fssum, mostly used for btrfs test cases that test the btrfs send feature, ignores completely the existence of xattrs. This change teaches fssum to find xattrs and make them contribute to the checksum of a filesystem, so that we can catch filesystem bugs regarding missing, corrupt or not supposed to exist xattrs (i.e. that an incremental btrfs send does not forget to create, update or remove xattrs). Signed-off-by: Filipe Manana --- src/fssum.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 129 insertions(+), 14 deletions(-) diff --git a/src/fssum.c b/src/fssum.c index f1da72fb..6ba0a95c 100644 --- a/src/fssum.c +++ b/src/fssum.c @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef __SOLARIS__ #include #endif @@ -40,7 +41,6 @@ #endif /* TODO: add hardlink recognition */ -/* TODO: add xattr/acl */ struct excludes { char *path; @@ -71,15 +71,16 @@ enum _flags { FLAG_MTIME, FLAG_CTIME, FLAG_DATA, + FLAG_XATTRS, FLAG_OPEN_ERROR, FLAG_STRUCTURE, NUM_FLAGS }; -const char flchar[] = "ugoamcdes"; +const char flchar[] = "ugoamcdxes"; char line[65536]; -int flags[NUM_FLAGS] = {1, 1, 1, 1, 1, 0, 1, 0, 0}; +int flags[NUM_FLAGS] = {1, 1, 1, 1, 1, 0, 1, 1, 0, 0}; char * getln(char *buf, int size, FILE *fp) @@ -135,7 +136,7 @@ usage(void) fprintf(stderr, " -v : verbose mode (debugging only)\n"); fprintf(stderr, " -r : read checksum or manifest from file\n"); - fprintf(stderr, " -[ugoamcde] : specify which fields to include in checksum calculation.\n"); + fprintf(stderr, " -[ugoamcdxe]: specify which fields to include in checksum calculation.\n"); fprintf(stderr, " u : include uid\n"); fprintf(stderr, " g : include gid\n"); fprintf(stderr, " o : include mode\n"); @@ -143,9 +144,10 @@ usage(void) fprintf(stderr, " a : include atime\n"); fprintf(stderr, " c : include ctime\n"); fprintf(stderr, " d : include file data\n"); + fprintf(stderr, " x : include xattrs\n"); fprintf(stderr, " e : include open errors (aborts otherwise)\n"); fprintf(stderr, " s : include block structure (holes)\n"); - fprintf(stderr, " -[UGOAMCDES]: exclude respective field from calculation\n"); + fprintf(stderr, " -[UGOAMCDXES]: exclude respective field from calculation\n"); fprintf(stderr, " -n : reset all flags\n"); fprintf(stderr, " -N : set all flags\n"); fprintf(stderr, " -x path : exclude path when building checksum (multiple ok)\n"); @@ -221,6 +223,106 @@ sum_to_string(sum_t *dst) } int +namecmp(const void *aa, const void *bb) +{ + char * const *a = aa; + char * const *b = bb; + + return strcmp(*a, *b); +} + +int +sum_xattrs(int fd, sum_t *dst) +{ + ssize_t buflen; + ssize_t len; + char *buf; + char *p; + char **names = NULL; + int num_xattrs = 0; + int ret = 0; + int i; + + buflen = flistxattr(fd, NULL, 0); + if (buflen < 0) + return -errno; + /* no xattrs exist */ + if (buflen == 0) + return 0; + + buf = malloc(buflen); + if (!buf) + return -ENOMEM; + + buflen = flistxattr(fd, buf, buflen); + if (buflen < 0) { + ret = -errno; + goto out; + } + + /* + * Keep the list of xattrs sorted, because the order in which they are + * listed is filesystem dependent, so we want to get the same checksum + * on different filesystems. + */ + + p = buf; + len = buflen; + while (len > 0) { + int keylen; + + keylen = strlen(p) + 1; /* +1 for NULL terminator */ + len -= keylen; + p += keylen; + num_xattrs++; + } + + names = malloc(sizeof(char *) * num_xattrs); + if (!names) { + ret = -ENOMEM; + goto out; + } + + p = buf; + for (i = 0; i < num_xattrs; i++) { + names[i] = p; + p += strlen(p) + 1; /* +1 for NULL terminator */ + } + + qsort(names, num_xattrs, sizeof(char *), namecmp); + + for (i = 0; i < num_xattrs; i++) { + len = fgetxattr(fd, names[i], NULL, 0); + if (len < 0) { + ret = -errno; + goto out; + } + sum_add(dst, names[i], strlen(names[i])); + /* no value */ + if (len == 0) + continue; + p = malloc(len); + if (!p) { + ret = -ENOMEM; + goto out; + } + len = fgetxattr(fd, names[i], p, len); + if (len < 0) { + ret = -errno; + free(p); + goto out; + } + sum_add(dst, p, len); + free(p); + } +out: + free(buf); + free(names); + + return ret; +} + +int sum_file_data_permissive(int fd, sum_t *dst) { int ret; @@ -401,15 +503,6 @@ malformed: excess_file(fn); } -int -namecmp(const void *aa, const void *bb) -{ - char * const *a = aa; - char * const *b = bb; - - return strcmp(*a, *b); -} - void sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in) { @@ -493,6 +586,28 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in) sum_add_time(&meta, st.st_mtime); if (flags[FLAG_CTIME]) sum_add_time(&meta, st.st_ctime); + if (flags[FLAG_XATTRS] && + (S_ISDIR(st.st_mode) || S_ISREG(st.st_mode))) { + fd = openat(dirfd, namelist[i], 0); + if (fd == -1 && flags[FLAG_OPEN_ERROR]) { + sum_add_u64(&meta, errno); + } else if (fd == -1) { + fprintf(stderr, "open failed for %s/%s: %s\n", + path_prefix, path, strerror(errno)); + exit(-1); + } else { + ret = sum_xattrs(fd, &meta); + close(fd); + if (ret < 0) { + fprintf(stderr, + "failed to read xattrs from " + "%s/%s: %s\n", + path_prefix, path, + strerror(-ret)); + exit(-1); + } + } + } if (S_ISDIR(st.st_mode)) { fd = openat(dirfd, namelist[i], 0); if (fd == -1 && flags[FLAG_OPEN_ERROR]) {