public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: sandeen@sandeen.net, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 1/2] xfs_db: add a directory path lookup command
Date: Wed, 28 Oct 2020 11:35:51 +1100	[thread overview]
Message-ID: <20201028003551.GZ7391@dread.disaster.area> (raw)
In-Reply-To: <160375515483.880118.8069916247570952970.stgit@magnolia>

On Mon, Oct 26, 2020 at 04:32:34PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Add a command to xfs_db so that we can navigate to inodes by path.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
....
> +/* Given a directory and a structured path, walk the path and set the cursor. */
> +static int
> +path_navigate(
> +	struct xfs_mount	*mp,
> +	xfs_ino_t		rootino,
> +	struct dirpath		*dirpath)
> +{
> +	struct xfs_inode	*dp;
> +	xfs_ino_t		ino = rootino;
> +	unsigned int		i;
> +	int			error;
> +
> +	error = -libxfs_iget(mp, NULL, ino, 0, &dp);
> +	if (error)
> +		return error;
> +
> +	for (i = 0; i < dirpath->depth; i++) {
> +		struct xfs_name	xname = {
> +			.name	= dirpath->path[i],
> +			.len	= strlen(dirpath->path[i]),
> +		};
> +
> +		if (!S_ISDIR(VFS_I(dp)->i_mode)) {
> +			error = ENOTDIR;
> +			goto rele;
> +		}
> +
> +		error = -libxfs_dir_lookup(NULL, dp, &xname, &ino, NULL);
> +		if (error)
> +			goto rele;
> +		if (!xfs_verify_ino(mp, ino)) {
> +			error = EFSCORRUPTED;
> +			goto rele;
> +		}
> +
> +		libxfs_irele(dp);
> +		dp = NULL;
> +
> +		error = -libxfs_iget(mp, NULL, ino, 0, &dp);
> +		switch (error) {
> +		case EFSCORRUPTED:
> +		case EFSBADCRC:
> +		case 0:
> +			break;
> +		default:
> +			return error;
> +		}
> +	}
> +
> +	set_cur_inode(ino);
> +rele:
> +	if (dp)
> +		libxfs_irele(dp);
> +	return error;
> +}

This could return negative errors....

> +/* Walk a directory path to an inode and set the io cursor to that inode. */
> +static int
> +path_walk(
> +	char		*path)
> +{
> +	struct dirpath	*dirpath;
> +	char		*p = path;
> +	xfs_ino_t	rootino = mp->m_sb.sb_rootino;
> +	int		ret = 0;
> +
> +	if (*p == '/') {
> +		/* Absolute path, start from the root inode. */
> +		p++;
> +	} else {
> +		/* Relative path, start from current dir. */
> +		if (iocur_top->typ != &typtab[TYP_INODE]) {
> +			dbprintf(_("current object is not an inode.\n"));
> +			return -1;
> +		}
> +
> +		if (!S_ISDIR(iocur_top->mode)) {
> +			dbprintf(_("current inode %llu is not a directory.\n"),
> +					(unsigned long long)iocur_top->ino);
> +			return -1;
> +		}
> +		rootino = iocur_top->ino;
> +	}
> +
> +	dirpath = path_parse(p);
> +	if (!dirpath) {
> +		dbprintf(_("%s: not enough memory to parse.\n"), path);
> +		return -1;
> +	}

and this could return -ENOMEM here with no error message....

> +
> +	ret = path_navigate(mp, rootino, dirpath);
> +	if (ret) {
> +		dbprintf(_("%s: %s\n"), path, strerror(ret));
> +		ret = -1;
> +	}

... don't overwrite ret here, move the dbprintf() to the caller and
the one error message captures all possible errors.

Also, no need for _() for a format string that contains no
translatable text....

Otherwise, looks fine.

-Dave.
-- 
Dave Chinner
david@fromorbit.com

  reply	other threads:[~2020-10-29  2:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 23:32 [PATCH 0/2] xfs_db: add minimal directory navigation Darrick J. Wong
2020-10-26 23:32 ` [PATCH 1/2] xfs_db: add a directory path lookup command Darrick J. Wong
2020-10-28  0:35   ` Dave Chinner [this message]
2020-10-29 18:38     ` Darrick J. Wong
2020-11-15 16:30   ` Eric Sandeen
2020-10-26 23:32 ` [PATCH 2/2] xfs_db: add an ls command Darrick J. Wong
2020-10-28  1:27   ` Dave Chinner
2020-10-28 22:50     ` Darrick J. Wong
2020-10-28 23:20       ` Dave Chinner
2020-10-29 18:41         ` Darrick J. Wong
  -- strict thread matches above, loose matches on Subject: below --
2020-11-16 17:35 [PATCH v2 0/2] xfs_db: add minimal directory navigation Darrick J. Wong
2020-11-16 17:35 ` [PATCH 1/2] xfs_db: add a directory path lookup command Darrick J. Wong
2020-11-25 20:38 [PATCH v3 0/2] xfs_db: add minimal directory navigation Darrick J. Wong
2020-11-25 20:38 ` [PATCH 1/2] xfs_db: add a directory path lookup command Darrick J. Wong
2020-12-01 10:16   ` Christoph Hellwig
2021-01-09  6:27 [PATCHSET v3 0/2] xfs_db: add minimal directory navigation Darrick J. Wong
2021-01-09  6:27 ` [PATCH 1/2] xfs_db: add a directory path lookup command Darrick J. Wong
2021-01-16  1:24 [PATCHSET v3 0/2] xfs_db: add minimal directory navigation Darrick J. Wong
2021-01-16  1:24 ` [PATCH 1/2] xfs_db: add a directory path lookup command Darrick J. Wong
2021-01-20 12:35   ` Chandan Babu R
2021-01-20 17:39     ` Darrick J. Wong
2021-02-03 19:42 [PATCHSET v4 0/2] xfs_db: add minimal directory navigation Darrick J. Wong
2021-02-03 19:43 ` [PATCH 1/2] xfs_db: add a directory path lookup command Darrick J. Wong
2021-02-04  9:39   ` Chandan Babu R
2021-02-09  4:09 [PATCHSET v5 0/2] xfs_db: add minimal directory navigation Darrick J. Wong
2021-02-09  4:09 ` [PATCH 1/2] xfs_db: add a directory path lookup command Darrick J. Wong

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=20201028003551.GZ7391@dread.disaster.area \
    --to=david@fromorbit.com \
    --cc=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    /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