public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Bill Kendall <wkendall@sgi.com>
To: xfs@oss.sgi.com
Subject: [PATCH 1/2]  add lpath_to_handle to libhandle
Date: Thu, 22 Oct 2009 11:52:23 -0500	[thread overview]
Message-ID: <4AE08DC7.7000200@sgi.com> (raw)

path_to_handle() is not reliable when called on a path which
is a symlink. If the symlink is dangling, or if its points
to a non-XFS filesystem then path_to_handle() will fail. The
reason is that path_to_handle() must open the path in order
to obtain an fd for the xfsctl call.

It's common during xfsrestore to have dangling symlinks since
the target of the link may not be restored before the symlink.

This patch adds a new function to libhandle, lpath_to_handle.
It is just like path_to_handle, except it takes a filesystem
path in addition to the path which you want convert to a
handle.

Alex Elder is going to take care of bumping the libhandle
minor number, and adjusting the xfsdump/xfsprogs version numbers
and dependencies to ensure a compatible libhandle is installed
for xfsdump.

Signed-off-by: Bill Kendall <wkendall@sgi.com>

diff --git a/include/handle.h b/include/handle.h
index b211a2f..3f1a137 100644
--- a/include/handle.h
+++ b/include/handle.h
@@ -27,6 +27,8 @@ struct attrlist_cursor;
  struct parent;

  extern int  path_to_handle (char *__path, void **__hanp, size_t *__hlen);
+extern int  lpath_to_handle (char *__fspath, char *__path,
+			     void **__hanp, size_t *__hlen);
  extern int  path_to_fshandle (char *__path, void **__fshanp, size_t *__fshlen);
  extern int  handle_to_fshandle (void *__hanp, size_t __hlen, void **__fshanp,
  				size_t *__fshlen);
diff --git a/libhandle/handle.c b/libhandle/handle.c
index 6276797..6c9380d 100644
--- a/libhandle/handle.c
+++ b/libhandle/handle.c
@@ -111,16 +111,29 @@ path_to_handle(
  	void		**hanp,		/* output, pointer to data */
  	size_t		*hlen)		/* output, size of returned data */
  {
+	return lpath_to_handle(path, path, hanp, hlen);
+}
+
+/* Like path_to_handle, but reliable for paths which are either dangling
+ * symlinks or symlinks whose targets are not in XFS filesystems.
+ */
+int
+lpath_to_handle(
+	char		*fspath,	/* input,  path in filesystem */
+	char		*path,		/* input,  path to convert */
+	void		**hanp,		/* output, pointer to data */
+	size_t		*hlen)		/* output, size of returned data */
+{
  	int		fd;
  	int		result;
  	comarg_t	obj;

-	fd = open(path, O_RDONLY);
+	fd = open(fspath, O_RDONLY);
  	if (fd < 0)
  		return -1;

  	obj.path = path;
-	result = obj_to_handle(path, fd, XFS_IOC_PATH_TO_HANDLE,
+	result = obj_to_handle(fspath, fd, XFS_IOC_PATH_TO_HANDLE,
  				obj, hanp, hlen);
  	close(fd);
  	return result;

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

             reply	other threads:[~2009-10-22 16:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-22 16:52 Bill Kendall [this message]
2009-10-23 18:08 ` [PATCH 1/2] add lpath_to_handle to libhandle Alex Elder
2009-10-24 13:37   ` Christoph Hellwig
2009-10-25  2:52     ` Christoph Hellwig
2009-10-24 13:39 ` Christoph Hellwig
2009-12-21 23:56   ` Bill Kendall
2009-12-23 13:15     ` Christoph Hellwig
2009-12-23 19:21       ` Bill Kendall
2010-01-06 17:41     ` Christoph Hellwig
2009-10-25  3:44 ` Christoph Hellwig

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=4AE08DC7.7000200@sgi.com \
    --to=wkendall@sgi.com \
    --cc=xfs@oss.sgi.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