linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHSET v2 0/4] various: random fixes
@ 2021-01-16  1:25 Darrick J. Wong
  2021-01-16  1:25 ` [PATCH 1/4] misc: fix valgrind complaints Darrick J. Wong
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Darrick J. Wong @ 2021-01-16  1:25 UTC (permalink / raw)
  To: sandeen, djwong; +Cc: linux-xfs

Hi all,

Here are some random fixes to the utilities: the first shuts up valgrind
warnings about uninitialized userspace memory being passed into kernel
ioctls; the second fixes warnings about libicu not being released at the
end of scrub; and the third fixes false collision reports during scrub
phase 5 if someone is replacing directory items while the scanner is
running.

v2: respond to reviewer comments

If you're going to start using this mess, you probably ought to just
pull from my git trees, which are linked below.

This is an extraordinary way to destroy everything.  Enjoy!
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=random-fixes

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=random-fixes

fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=random-fixes
---
 libhandle/handle.c |   10 ++++++----
 scrub/inodes.c     |   18 +++++++++++++++++-
 scrub/spacemap.c   |    3 +--
 scrub/unicrash.c   |   33 ++++++++++++++++++++++++++++++++-
 scrub/unicrash.h   |    4 ++++
 scrub/xfs_scrub.c  |    6 ++++++
 6 files changed, 66 insertions(+), 8 deletions(-)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/4] misc: fix valgrind complaints
  2021-01-16  1:25 [PATCHSET v2 0/4] various: random fixes Darrick J. Wong
@ 2021-01-16  1:25 ` Darrick J. Wong
  2021-01-18  4:33   ` Chandan Babu R
  2021-01-19  2:55   ` Chaitanya Kulkarni
  2021-01-16  1:25 ` [PATCH 2/4] xfs_scrub: detect infinite loops when scanning inodes Darrick J. Wong
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 11+ messages in thread
From: Darrick J. Wong @ 2021-01-16  1:25 UTC (permalink / raw)
  To: sandeen, djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

Zero the memory that we pass to the kernel via ioctls so that we never
pass userspace heap/stack garbage around.  This silences valgrind
complaints about uninitialized padding areas.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 libhandle/handle.c |   10 ++++++----
 scrub/inodes.c     |    2 +-
 scrub/spacemap.c   |    3 +--
 3 files changed, 8 insertions(+), 7 deletions(-)


diff --git a/libhandle/handle.c b/libhandle/handle.c
index 5c1686b3..27abc6b2 100644
--- a/libhandle/handle.c
+++ b/libhandle/handle.c
@@ -235,8 +235,10 @@ obj_to_handle(
 {
 	char		hbuf [MAXHANSIZ];
 	int		ret;
-	uint32_t	handlen;
-	xfs_fsop_handlereq_t hreq;
+	uint32_t	handlen = 0;
+	struct xfs_fsop_handlereq hreq = { };
+
+	memset(hbuf, 0, MAXHANSIZ);
 
 	if (opcode == XFS_IOC_FD_TO_HANDLE) {
 		hreq.fd      = obj.fd;
@@ -275,7 +277,7 @@ open_by_fshandle(
 {
 	int		fsfd;
 	char		*path;
-	xfs_fsop_handlereq_t hreq;
+	struct xfs_fsop_handlereq hreq = { };
 
 	if ((fsfd = handle_to_fsfd(fshanp, &path)) < 0)
 		return -1;
@@ -382,7 +384,7 @@ attr_list_by_handle(
 {
 	int		error, fd;
 	char		*path;
-	xfs_fsop_attrlist_handlereq_t alhreq;
+	struct xfs_fsop_attrlist_handlereq alhreq = { };
 
 	if ((fd = handle_to_fsfd(hanp, &path)) < 0)
 		return -1;
diff --git a/scrub/inodes.c b/scrub/inodes.c
index bdc12df3..63865113 100644
--- a/scrub/inodes.c
+++ b/scrub/inodes.c
@@ -111,7 +111,7 @@ scan_ag_inodes(
 	xfs_agnumber_t		agno,
 	void			*arg)
 {
-	struct xfs_handle	handle;
+	struct xfs_handle	handle = { };
 	char			descr[DESCR_BUFSZ];
 	struct xfs_inumbers_req	*ireq;
 	struct xfs_bulkstat_req	*breq;
diff --git a/scrub/spacemap.c b/scrub/spacemap.c
index 9653916d..a5508d56 100644
--- a/scrub/spacemap.c
+++ b/scrub/spacemap.c
@@ -47,11 +47,10 @@ scrub_iterate_fsmap(
 	int			i;
 	int			error;
 
-	head = malloc(fsmap_sizeof(FSMAP_NR));
+	head = calloc(1, fsmap_sizeof(FSMAP_NR));
 	if (!head)
 		return errno;
 
-	memset(head, 0, sizeof(*head));
 	memcpy(head->fmh_keys, keys, sizeof(struct fsmap) * 2);
 	head->fmh_count = FSMAP_NR;
 


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/4] xfs_scrub: detect infinite loops when scanning inodes
  2021-01-16  1:25 [PATCHSET v2 0/4] various: random fixes Darrick J. Wong
  2021-01-16  1:25 ` [PATCH 1/4] misc: fix valgrind complaints Darrick J. Wong
@ 2021-01-16  1:25 ` Darrick J. Wong
  2021-01-18  4:57   ` Chandan Babu R
  2021-01-16  1:25 ` [PATCH 3/4] xfs_scrub: load and unload libicu properly Darrick J. Wong
  2021-01-16  1:25 ` [PATCH 4/4] xfs_scrub: handle concurrent directory updates during name scan Darrick J. Wong
  3 siblings, 1 reply; 11+ messages in thread
From: Darrick J. Wong @ 2021-01-16  1:25 UTC (permalink / raw)
  To: sandeen, djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

During an inode scan (aka phase 3) when we're scanning the inode btree
to find files to check, make sure that each invocation of inumbers
actually gives us an inobt record with a startino that's at least as
large as what we asked for so that we always make forward progress.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 scrub/inodes.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)


diff --git a/scrub/inodes.c b/scrub/inodes.c
index 63865113..cc73da7f 100644
--- a/scrub/inodes.c
+++ b/scrub/inodes.c
@@ -119,6 +119,7 @@ scan_ag_inodes(
 	struct scrub_ctx	*ctx = (struct scrub_ctx *)wq->wq_ctx;
 	struct xfs_bulkstat	*bs;
 	struct xfs_inumbers	*inumbers;
+	uint64_t		nextino = cvt_agino_to_ino(&ctx->mnt, agno, 0);
 	int			i;
 	int			error;
 	int			stale_count = 0;
@@ -153,6 +154,21 @@ scan_ag_inodes(
 	/* Find the inode chunk & alloc mask */
 	error = -xfrog_inumbers(&ctx->mnt, ireq);
 	while (!error && !si->aborted && ireq->hdr.ocount > 0) {
+		/*
+		 * Make sure that we always make forward progress while we
+		 * scan the inode btree.
+		 */
+		if (nextino > inumbers->xi_startino) {
+			str_corrupt(ctx, descr,
+	_("AG %u inode btree is corrupt near agino %lu, got %lu"), agno,
+				cvt_ino_to_agino(&ctx->mnt, nextino),
+				cvt_ino_to_agino(&ctx->mnt,
+						ireq->inumbers[0].xi_startino));
+			si->aborted = true;
+			break;
+		}
+		nextino = ireq->hdr.ino;
+
 		/*
 		 * We can have totally empty inode chunks on filesystems where
 		 * there are more than 64 inodes per block.  Skip these.


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/4] xfs_scrub: load and unload libicu properly
  2021-01-16  1:25 [PATCHSET v2 0/4] various: random fixes Darrick J. Wong
  2021-01-16  1:25 ` [PATCH 1/4] misc: fix valgrind complaints Darrick J. Wong
  2021-01-16  1:25 ` [PATCH 2/4] xfs_scrub: detect infinite loops when scanning inodes Darrick J. Wong
@ 2021-01-16  1:25 ` Darrick J. Wong
  2021-01-18  4:45   ` Chandan Babu R
  2021-01-18 19:19   ` [PATCH v2.1 " Darrick J. Wong
  2021-01-16  1:25 ` [PATCH 4/4] xfs_scrub: handle concurrent directory updates during name scan Darrick J. Wong
  3 siblings, 2 replies; 11+ messages in thread
From: Darrick J. Wong @ 2021-01-16  1:25 UTC (permalink / raw)
  To: sandeen, djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

Make sure we actually load and unload libicu properly.  This isn't
strictly required since the library can bootstrap itself, but unloading
means fewer things for valgrind to complain about.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 scrub/unicrash.c  |   17 +++++++++++++++++
 scrub/unicrash.h  |    4 ++++
 scrub/xfs_scrub.c |    6 ++++++
 3 files changed, 27 insertions(+)


diff --git a/scrub/unicrash.c b/scrub/unicrash.c
index d5d2cf20..de3217c2 100644
--- a/scrub/unicrash.c
+++ b/scrub/unicrash.c
@@ -722,3 +722,20 @@ unicrash_check_fs_label(
 	return __unicrash_check_name(uc, dsc, _("filesystem label"),
 			label, 0);
 }
+
+/* Load libicu and initialize it. */
+bool
+unicrash_load(void)
+{
+	UErrorCode		uerr = U_ZERO_ERROR;
+
+	u_init(&uerr);
+	return U_FAILURE(uerr);
+}
+
+/* Unload libicu once we're done with it. */
+void
+unicrash_unload(void)
+{
+	u_cleanup();
+}
diff --git a/scrub/unicrash.h b/scrub/unicrash.h
index c3a7f385..755afaef 100644
--- a/scrub/unicrash.h
+++ b/scrub/unicrash.h
@@ -25,6 +25,8 @@ int unicrash_check_xattr_name(struct unicrash *uc, struct descr *dsc,
 		const char *attrname);
 int unicrash_check_fs_label(struct unicrash *uc, struct descr *dsc,
 		const char *label);
+bool unicrash_load(void);
+void unicrash_unload(void);
 #else
 # define unicrash_dir_init(u, c, b)		(0)
 # define unicrash_xattr_init(u, c, b)		(0)
@@ -33,6 +35,8 @@ int unicrash_check_fs_label(struct unicrash *uc, struct descr *dsc,
 # define unicrash_check_dir_name(u, d, n)	(0)
 # define unicrash_check_xattr_name(u, d, n)	(0)
 # define unicrash_check_fs_label(u, d, n)	(0)
+# define unicrash_load()			(0)
+# define unicrash_unload()			do { } while (0)
 #endif /* HAVE_LIBICU */
 
 #endif /* XFS_SCRUB_UNICRASH_H_ */
diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c
index 1edeb150..6b202912 100644
--- a/scrub/xfs_scrub.c
+++ b/scrub/xfs_scrub.c
@@ -603,6 +603,11 @@ main(
 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
+	if (unicrash_load()) {
+		fprintf(stderr,
+			_("%s: could initialize Unicode library.\n"), progname);
+		goto out;
+	}
 
 	pthread_mutex_init(&ctx.lock, NULL);
 	ctx.mode = SCRUB_MODE_REPAIR;
@@ -788,6 +793,7 @@ main(
 	phase_end(&all_pi, 0);
 	if (progress_fp)
 		fclose(progress_fp);
+	unicrash_unload();
 
 	/*
 	 * If we're being run as a service, the return code must fit the LSB


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/4] xfs_scrub: handle concurrent directory updates during name scan
  2021-01-16  1:25 [PATCHSET v2 0/4] various: random fixes Darrick J. Wong
                   ` (2 preceding siblings ...)
  2021-01-16  1:25 ` [PATCH 3/4] xfs_scrub: load and unload libicu properly Darrick J. Wong
@ 2021-01-16  1:25 ` Darrick J. Wong
  2021-01-18  4:47   ` Chandan Babu R
  3 siblings, 1 reply; 11+ messages in thread
From: Darrick J. Wong @ 2021-01-16  1:25 UTC (permalink / raw)
  To: sandeen, djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

The name scanner in xfs_scrub cannot lock a namespace (dirent or xattr)
and the kernel does not provide a stable cursor interface, which means
that we can see the same byte sequence multiple times during a scan.
This isn't a confusing name error since the kernel enforces uniqueness
on the byte sequence, so all we need to do here is update the old entry.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 scrub/unicrash.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)


diff --git a/scrub/unicrash.c b/scrub/unicrash.c
index de3217c2..cb0880c1 100644
--- a/scrub/unicrash.c
+++ b/scrub/unicrash.c
@@ -68,7 +68,7 @@ struct name_entry {
 
 	xfs_ino_t		ino;
 
-	/* Raw UTF8 name */
+	/* Raw dirent name */
 	size_t			namelen;
 	char			name[0];
 };
@@ -627,6 +627,20 @@ unicrash_add(
 	uc->buckets[bucket] = new_entry;
 
 	while (entry != NULL) {
+		/*
+		 * If we see the same byte sequence then someone's modifying
+		 * the namespace while we're scanning it.  Update the existing
+		 * entry's inode mapping and erase the new entry from existence.
+		 */
+		if (new_entry->namelen == entry->namelen &&
+		    !memcmp(new_entry->name, entry->name, entry->namelen)) {
+			entry->ino = new_entry->ino;
+			uc->buckets[bucket] = new_entry->next;
+			name_entry_free(new_entry);
+			*badflags = 0;
+			return;
+		}
+
 		/* Same normalization? */
 		if (new_entry->normstrlen == entry->normstrlen &&
 		    !u_strcmp(new_entry->normstr, entry->normstr) &&


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/4] misc: fix valgrind complaints
  2021-01-16  1:25 ` [PATCH 1/4] misc: fix valgrind complaints Darrick J. Wong
@ 2021-01-18  4:33   ` Chandan Babu R
  2021-01-19  2:55   ` Chaitanya Kulkarni
  1 sibling, 0 replies; 11+ messages in thread
From: Chandan Babu R @ 2021-01-18  4:33 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs


On 16 Jan 2021 at 06:55, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> Zero the memory that we pass to the kernel via ioctls so that we never
> pass userspace heap/stack garbage around.  This silences valgrind
> complaints about uninitialized padding areas.
>

Looks good to me,

Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>

> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
>  libhandle/handle.c |   10 ++++++----
>  scrub/inodes.c     |    2 +-
>  scrub/spacemap.c   |    3 +--
>  3 files changed, 8 insertions(+), 7 deletions(-)
>
>
> diff --git a/libhandle/handle.c b/libhandle/handle.c
> index 5c1686b3..27abc6b2 100644
> --- a/libhandle/handle.c
> +++ b/libhandle/handle.c
> @@ -235,8 +235,10 @@ obj_to_handle(
>  {
>  	char		hbuf [MAXHANSIZ];
>  	int		ret;
> -	uint32_t	handlen;
> -	xfs_fsop_handlereq_t hreq;
> +	uint32_t	handlen = 0;
> +	struct xfs_fsop_handlereq hreq = { };
> +
> +	memset(hbuf, 0, MAXHANSIZ);
>  
>  	if (opcode == XFS_IOC_FD_TO_HANDLE) {
>  		hreq.fd      = obj.fd;
> @@ -275,7 +277,7 @@ open_by_fshandle(
>  {
>  	int		fsfd;
>  	char		*path;
> -	xfs_fsop_handlereq_t hreq;
> +	struct xfs_fsop_handlereq hreq = { };
>  
>  	if ((fsfd = handle_to_fsfd(fshanp, &path)) < 0)
>  		return -1;
> @@ -382,7 +384,7 @@ attr_list_by_handle(
>  {
>  	int		error, fd;
>  	char		*path;
> -	xfs_fsop_attrlist_handlereq_t alhreq;
> +	struct xfs_fsop_attrlist_handlereq alhreq = { };
>  
>  	if ((fd = handle_to_fsfd(hanp, &path)) < 0)
>  		return -1;
> diff --git a/scrub/inodes.c b/scrub/inodes.c
> index bdc12df3..63865113 100644
> --- a/scrub/inodes.c
> +++ b/scrub/inodes.c
> @@ -111,7 +111,7 @@ scan_ag_inodes(
>  	xfs_agnumber_t		agno,
>  	void			*arg)
>  {
> -	struct xfs_handle	handle;
> +	struct xfs_handle	handle = { };
>  	char			descr[DESCR_BUFSZ];
>  	struct xfs_inumbers_req	*ireq;
>  	struct xfs_bulkstat_req	*breq;
> diff --git a/scrub/spacemap.c b/scrub/spacemap.c
> index 9653916d..a5508d56 100644
> --- a/scrub/spacemap.c
> +++ b/scrub/spacemap.c
> @@ -47,11 +47,10 @@ scrub_iterate_fsmap(
>  	int			i;
>  	int			error;
>  
> -	head = malloc(fsmap_sizeof(FSMAP_NR));
> +	head = calloc(1, fsmap_sizeof(FSMAP_NR));
>  	if (!head)
>  		return errno;
>  
> -	memset(head, 0, sizeof(*head));
>  	memcpy(head->fmh_keys, keys, sizeof(struct fsmap) * 2);
>  	head->fmh_count = FSMAP_NR;
>  


-- 
chandan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/4] xfs_scrub: load and unload libicu properly
  2021-01-16  1:25 ` [PATCH 3/4] xfs_scrub: load and unload libicu properly Darrick J. Wong
@ 2021-01-18  4:45   ` Chandan Babu R
  2021-01-18 19:19   ` [PATCH v2.1 " Darrick J. Wong
  1 sibling, 0 replies; 11+ messages in thread
From: Chandan Babu R @ 2021-01-18  4:45 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs


On 16 Jan 2021 at 06:55, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> Make sure we actually load and unload libicu properly.  This isn't
> strictly required since the library can bootstrap itself, but unloading
> means fewer things for valgrind to complain about.
>
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
>  scrub/unicrash.c  |   17 +++++++++++++++++
>  scrub/unicrash.h  |    4 ++++
>  scrub/xfs_scrub.c |    6 ++++++
>  3 files changed, 27 insertions(+)
>
>
> diff --git a/scrub/unicrash.c b/scrub/unicrash.c
> index d5d2cf20..de3217c2 100644
> --- a/scrub/unicrash.c
> +++ b/scrub/unicrash.c
> @@ -722,3 +722,20 @@ unicrash_check_fs_label(
>  	return __unicrash_check_name(uc, dsc, _("filesystem label"),
>  			label, 0);
>  }
> +
> +/* Load libicu and initialize it. */
> +bool
> +unicrash_load(void)
> +{
> +	UErrorCode		uerr = U_ZERO_ERROR;
> +
> +	u_init(&uerr);
> +	return U_FAILURE(uerr);
> +}
> +
> +/* Unload libicu once we're done with it. */
> +void
> +unicrash_unload(void)
> +{
> +	u_cleanup();
> +}
> diff --git a/scrub/unicrash.h b/scrub/unicrash.h
> index c3a7f385..755afaef 100644
> --- a/scrub/unicrash.h
> +++ b/scrub/unicrash.h
> @@ -25,6 +25,8 @@ int unicrash_check_xattr_name(struct unicrash *uc, struct descr *dsc,
>  		const char *attrname);
>  int unicrash_check_fs_label(struct unicrash *uc, struct descr *dsc,
>  		const char *label);
> +bool unicrash_load(void);
> +void unicrash_unload(void);
>  #else
>  # define unicrash_dir_init(u, c, b)		(0)
>  # define unicrash_xattr_init(u, c, b)		(0)
> @@ -33,6 +35,8 @@ int unicrash_check_fs_label(struct unicrash *uc, struct descr *dsc,
>  # define unicrash_check_dir_name(u, d, n)	(0)
>  # define unicrash_check_xattr_name(u, d, n)	(0)
>  # define unicrash_check_fs_label(u, d, n)	(0)
> +# define unicrash_load()			(0)
> +# define unicrash_unload()			do { } while (0)
>  #endif /* HAVE_LIBICU */
>  
>  #endif /* XFS_SCRUB_UNICRASH_H_ */
> diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c
> index 1edeb150..6b202912 100644
> --- a/scrub/xfs_scrub.c
> +++ b/scrub/xfs_scrub.c
> @@ -603,6 +603,11 @@ main(
>  	setlocale(LC_ALL, "");
>  	bindtextdomain(PACKAGE, LOCALEDIR);
>  	textdomain(PACKAGE);
> +	if (unicrash_load()) {
> +		fprintf(stderr,
> +			_("%s: could initialize Unicode library.\n"), progname);

... "Couldn't initialize ..."

The rest looks good to me.

Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>

> +		goto out;
> +	}
>  
>  	pthread_mutex_init(&ctx.lock, NULL);
>  	ctx.mode = SCRUB_MODE_REPAIR;
> @@ -788,6 +793,7 @@ main(
>  	phase_end(&all_pi, 0);
>  	if (progress_fp)
>  		fclose(progress_fp);
> +	unicrash_unload();
>  
>  	/*
>  	 * If we're being run as a service, the return code must fit the LSB


-- 
chandan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/4] xfs_scrub: handle concurrent directory updates during name scan
  2021-01-16  1:25 ` [PATCH 4/4] xfs_scrub: handle concurrent directory updates during name scan Darrick J. Wong
@ 2021-01-18  4:47   ` Chandan Babu R
  0 siblings, 0 replies; 11+ messages in thread
From: Chandan Babu R @ 2021-01-18  4:47 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs


On 16 Jan 2021 at 06:55, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> The name scanner in xfs_scrub cannot lock a namespace (dirent or xattr)
> and the kernel does not provide a stable cursor interface, which means
> that we can see the same byte sequence multiple times during a scan.
> This isn't a confusing name error since the kernel enforces uniqueness
> on the byte sequence, so all we need to do here is update the old entry.
>

Looks good to me.

Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>

> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
>  scrub/unicrash.c |   16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
>
>
> diff --git a/scrub/unicrash.c b/scrub/unicrash.c
> index de3217c2..cb0880c1 100644
> --- a/scrub/unicrash.c
> +++ b/scrub/unicrash.c
> @@ -68,7 +68,7 @@ struct name_entry {
>  
>  	xfs_ino_t		ino;
>  
> -	/* Raw UTF8 name */
> +	/* Raw dirent name */
>  	size_t			namelen;
>  	char			name[0];
>  };
> @@ -627,6 +627,20 @@ unicrash_add(
>  	uc->buckets[bucket] = new_entry;
>  
>  	while (entry != NULL) {
> +		/*
> +		 * If we see the same byte sequence then someone's modifying
> +		 * the namespace while we're scanning it.  Update the existing
> +		 * entry's inode mapping and erase the new entry from existence.
> +		 */
> +		if (new_entry->namelen == entry->namelen &&
> +		    !memcmp(new_entry->name, entry->name, entry->namelen)) {
> +			entry->ino = new_entry->ino;
> +			uc->buckets[bucket] = new_entry->next;
> +			name_entry_free(new_entry);
> +			*badflags = 0;
> +			return;
> +		}
> +
>  		/* Same normalization? */
>  		if (new_entry->normstrlen == entry->normstrlen &&
>  		    !u_strcmp(new_entry->normstr, entry->normstr) &&


-- 
chandan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/4] xfs_scrub: detect infinite loops when scanning inodes
  2021-01-16  1:25 ` [PATCH 2/4] xfs_scrub: detect infinite loops when scanning inodes Darrick J. Wong
@ 2021-01-18  4:57   ` Chandan Babu R
  0 siblings, 0 replies; 11+ messages in thread
From: Chandan Babu R @ 2021-01-18  4:57 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs


On 16 Jan 2021 at 06:55, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> During an inode scan (aka phase 3) when we're scanning the inode btree
> to find files to check, make sure that each invocation of inumbers
> actually gives us an inobt record with a startino that's at least as
> large as what we asked for so that we always make forward progress.
>

Looks good to me,

Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>

> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
>  scrub/inodes.c |   16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
>
> diff --git a/scrub/inodes.c b/scrub/inodes.c
> index 63865113..cc73da7f 100644
> --- a/scrub/inodes.c
> +++ b/scrub/inodes.c
> @@ -119,6 +119,7 @@ scan_ag_inodes(
>  	struct scrub_ctx	*ctx = (struct scrub_ctx *)wq->wq_ctx;
>  	struct xfs_bulkstat	*bs;
>  	struct xfs_inumbers	*inumbers;
> +	uint64_t		nextino = cvt_agino_to_ino(&ctx->mnt, agno, 0);
>  	int			i;
>  	int			error;
>  	int			stale_count = 0;
> @@ -153,6 +154,21 @@ scan_ag_inodes(
>  	/* Find the inode chunk & alloc mask */
>  	error = -xfrog_inumbers(&ctx->mnt, ireq);
>  	while (!error && !si->aborted && ireq->hdr.ocount > 0) {
> +		/*
> +		 * Make sure that we always make forward progress while we
> +		 * scan the inode btree.
> +		 */
> +		if (nextino > inumbers->xi_startino) {
> +			str_corrupt(ctx, descr,
> +	_("AG %u inode btree is corrupt near agino %lu, got %lu"), agno,
> +				cvt_ino_to_agino(&ctx->mnt, nextino),
> +				cvt_ino_to_agino(&ctx->mnt,
> +						ireq->inumbers[0].xi_startino));
> +			si->aborted = true;
> +			break;
> +		}
> +		nextino = ireq->hdr.ino;
> +
>  		/*
>  		 * We can have totally empty inode chunks on filesystems where
>  		 * there are more than 64 inodes per block.  Skip these.


-- 
chandan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2.1 3/4] xfs_scrub: load and unload libicu properly
  2021-01-16  1:25 ` [PATCH 3/4] xfs_scrub: load and unload libicu properly Darrick J. Wong
  2021-01-18  4:45   ` Chandan Babu R
@ 2021-01-18 19:19   ` Darrick J. Wong
  1 sibling, 0 replies; 11+ messages in thread
From: Darrick J. Wong @ 2021-01-18 19:19 UTC (permalink / raw)
  To: sandeen; +Cc: linux-xfs, chandanrlinux

From: Darrick J. Wong <djwong@kernel.org>

Make sure we actually load and unload libicu properly.  This isn't
strictly required since the library can bootstrap itself, but unloading
means fewer things for valgrind to complain about.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
---
v2.1: fix error message
---
 scrub/unicrash.c  |   17 +++++++++++++++++
 scrub/unicrash.h  |    4 ++++
 scrub/xfs_scrub.c |    7 +++++++
 3 files changed, 28 insertions(+)

diff --git a/scrub/unicrash.c b/scrub/unicrash.c
index d5d2cf20..de3217c2 100644
--- a/scrub/unicrash.c
+++ b/scrub/unicrash.c
@@ -722,3 +722,20 @@ unicrash_check_fs_label(
 	return __unicrash_check_name(uc, dsc, _("filesystem label"),
 			label, 0);
 }
+
+/* Load libicu and initialize it. */
+bool
+unicrash_load(void)
+{
+	UErrorCode		uerr = U_ZERO_ERROR;
+
+	u_init(&uerr);
+	return U_FAILURE(uerr);
+}
+
+/* Unload libicu once we're done with it. */
+void
+unicrash_unload(void)
+{
+	u_cleanup();
+}
diff --git a/scrub/unicrash.h b/scrub/unicrash.h
index c3a7f385..755afaef 100644
--- a/scrub/unicrash.h
+++ b/scrub/unicrash.h
@@ -25,6 +25,8 @@ int unicrash_check_xattr_name(struct unicrash *uc, struct descr *dsc,
 		const char *attrname);
 int unicrash_check_fs_label(struct unicrash *uc, struct descr *dsc,
 		const char *label);
+bool unicrash_load(void);
+void unicrash_unload(void);
 #else
 # define unicrash_dir_init(u, c, b)		(0)
 # define unicrash_xattr_init(u, c, b)		(0)
@@ -33,6 +35,8 @@ int unicrash_check_fs_label(struct unicrash *uc, struct descr *dsc,
 # define unicrash_check_dir_name(u, d, n)	(0)
 # define unicrash_check_xattr_name(u, d, n)	(0)
 # define unicrash_check_fs_label(u, d, n)	(0)
+# define unicrash_load()			(0)
+# define unicrash_unload()			do { } while (0)
 #endif /* HAVE_LIBICU */
 
 #endif /* XFS_SCRUB_UNICRASH_H_ */
diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c
index 1edeb150..bc2e84a7 100644
--- a/scrub/xfs_scrub.c
+++ b/scrub/xfs_scrub.c
@@ -603,6 +603,12 @@ main(
 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
+	if (unicrash_load()) {
+		fprintf(stderr,
+	_("%s: couldn't initialize Unicode library.\n"),
+				progname);
+		goto out;
+	}
 
 	pthread_mutex_init(&ctx.lock, NULL);
 	ctx.mode = SCRUB_MODE_REPAIR;
@@ -788,6 +794,7 @@ main(
 	phase_end(&all_pi, 0);
 	if (progress_fp)
 		fclose(progress_fp);
+	unicrash_unload();
 
 	/*
 	 * If we're being run as a service, the return code must fit the LSB

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/4] misc: fix valgrind complaints
  2021-01-16  1:25 ` [PATCH 1/4] misc: fix valgrind complaints Darrick J. Wong
  2021-01-18  4:33   ` Chandan Babu R
@ 2021-01-19  2:55   ` Chaitanya Kulkarni
  1 sibling, 0 replies; 11+ messages in thread
From: Chaitanya Kulkarni @ 2021-01-19  2:55 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

On 1/15/21 5:28 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> Zero the memory that we pass to the kernel via ioctls so that we never
> pass userspace heap/stack garbage around.  This silences valgrind
> complaints about uninitialized padding areas.
>
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Looks good.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-01-19  2:56 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-16  1:25 [PATCHSET v2 0/4] various: random fixes Darrick J. Wong
2021-01-16  1:25 ` [PATCH 1/4] misc: fix valgrind complaints Darrick J. Wong
2021-01-18  4:33   ` Chandan Babu R
2021-01-19  2:55   ` Chaitanya Kulkarni
2021-01-16  1:25 ` [PATCH 2/4] xfs_scrub: detect infinite loops when scanning inodes Darrick J. Wong
2021-01-18  4:57   ` Chandan Babu R
2021-01-16  1:25 ` [PATCH 3/4] xfs_scrub: load and unload libicu properly Darrick J. Wong
2021-01-18  4:45   ` Chandan Babu R
2021-01-18 19:19   ` [PATCH v2.1 " Darrick J. Wong
2021-01-16  1:25 ` [PATCH 4/4] xfs_scrub: handle concurrent directory updates during name scan Darrick J. Wong
2021-01-18  4:47   ` Chandan Babu R

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).