public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][V4] misc: copy extended attributes in populate_fs
@ 2014-07-10 16:44 Ross Burton
  2014-07-28  1:29 ` [V4] " Theodore Ts'o
  0 siblings, 1 reply; 5+ messages in thread
From: Ross Burton @ 2014-07-10 16:44 UTC (permalink / raw)
  To: linux-ext4; +Cc: darrick.wong, tytso

When creating a file system using a source directory, also copy any extended
attributes that have been set.

Signed-off-by: Ross Burton <ross.burton@intel.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 misc/create_inode.c |   90 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/misc/create_inode.c b/misc/create_inode.c
index c9c99b5..660a294 100644
--- a/misc/create_inode.c
+++ b/misc/create_inode.c
@@ -103,6 +103,89 @@ static errcode_t set_inode_extra(ext2_filsys fs, ext2_ino_t cwd,
 	return retval;
 }
 
+static errcode_t set_inode_xattr(ext2_filsys fs, ext2_ino_t ino, const char *filename)
+{
+	errcode_t			retval, close_retval;
+	struct ext2_inode		inode;
+	struct ext2_xattr_handle	*handle;
+	ssize_t				size, value_size;
+	char				*list;
+	int				i;
+
+	size = llistxattr(filename, NULL, 0);
+	if (size == -1) {
+		com_err(__func__, errno, "llistxattr failed on %s", filename);
+		return errno;
+	} else if (size == 0) {
+		return 0;
+	}
+
+	retval = ext2fs_xattrs_open(fs, ino, &handle);
+	if (retval) {
+		if (retval == EXT2_ET_MISSING_EA_FEATURE)
+			return 0;
+		com_err(__func__, retval, "while opening inode %u", ino);
+		return retval;
+	}
+
+	retval = ext2fs_get_mem(size, &list);
+	if (retval) {
+		com_err(__func__, retval, "whilst allocating memory");
+		goto out;
+	}
+
+	size = llistxattr(filename, list, size);
+	if (size == -1) {
+		com_err(__func__, errno, "llistxattr failed on %s", filename);
+		retval = errno;
+		goto out;
+        }
+
+	for (i = 0; i < size; i += strlen(&list[i]) + 1) {
+		const char *name = &list[i];
+		char *value;
+
+		value_size = getxattr(filename, name, NULL, 0);
+		if (value_size == -1) {
+			com_err(__func__, errno, "getxattr failed on %s", filename);
+			retval = errno;
+			break;
+		}
+
+		retval = ext2fs_get_mem(value_size, &value);
+		if (retval) {
+			com_err(__func__, retval, "whilst allocating memory");
+			break;
+		}
+
+		value_size = getxattr(filename, name, value, value_size);
+		if (value_size == -1) {
+			ext2fs_free_mem(&value);
+			com_err(__func__, errno, "getxattr failed on %s", filename);
+			retval = errno;
+			break;
+		}
+
+		retval = ext2fs_xattr_set(handle, name, value, value_size);
+		ext2fs_free_mem(&value);
+		if (retval) {
+			com_err(__func__, retval, "while writing xattr %u", ino);
+			break;
+		}
+
+	}
+ out:
+	ext2fs_free_mem(&list);
+
+	close_retval = ext2fs_xattrs_close(&handle);
+	if (close_retval) {
+		com_err(__func__, retval, "while closing inode %u", ino);
+		retval = retval ? retval : close_retval;
+	}
+
+	return retval;
+}
+
 /* Make a special files (block and character devices), fifo's, and sockets  */
 errcode_t do_mknod_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name,
 			    struct stat *st)
@@ -615,6 +698,13 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
 			goto out;
 		}
 
+		retval = set_inode_xattr(fs, ino, name);
+		if (retval) {
+			com_err(__func__, retval,
+				_("while setting xattrs for \"%s\""), name);
+			goto out;
+		}
+
 		/* Save the hardlink ino */
 		if (save_inode) {
 			/*
-- 
1.7.10.4


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

* Re: [V4] misc: copy extended attributes in populate_fs
  2014-07-10 16:44 [PATCH][V4] misc: copy extended attributes in populate_fs Ross Burton
@ 2014-07-28  1:29 ` Theodore Ts'o
  2014-09-09 10:20   ` Burton, Ross
  0 siblings, 1 reply; 5+ messages in thread
From: Theodore Ts'o @ 2014-07-28  1:29 UTC (permalink / raw)
  To: Ross Burton; +Cc: linux-ext4, darrick.wong

On Thu, Jul 10, 2014 at 05:44:38PM +0100, Ross Burton wrote:
> When creating a file system using a source directory, also copy any extended
> attributes that have been set.
> 
> Signed-off-by: Ross Burton <ross.burton@intel.com>
> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

Applied, after I added configure tests to test for the Linux-specific
system calls, and to add a fallback in case we are compiling on a
non-Linux system.

					- Ted

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

* Re: [V4] misc: copy extended attributes in populate_fs
  2014-07-28  1:29 ` [V4] " Theodore Ts'o
@ 2014-09-09 10:20   ` Burton, Ross
  2014-09-09 13:03     ` Theodore Ts'o
  0 siblings, 1 reply; 5+ messages in thread
From: Burton, Ross @ 2014-09-09 10:20 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: linux-ext4

On 28 July 2014 02:29, Theodore Ts'o <tytso@mit.edu> wrote:
> On Thu, Jul 10, 2014 at 05:44:38PM +0100, Ross Burton wrote:
>> When creating a file system using a source directory, also copy any extended
>> attributes that have been set.
>>
>> Signed-off-by: Ross Burton <ross.burton@intel.com>
>> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
>
> Applied, after I added configure tests to test for the Linux-specific
> system calls, and to add a fallback in case we are compiling on a
> non-Linux system.

Thanks Ted.

I see that you merged before 1.42.12 was released but this didn't make
1.42.12.  Will it be in 1.42.13, or is it waiting for a 1.43.0
release?

Cheers
Ross

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

* Re: [V4] misc: copy extended attributes in populate_fs
  2014-09-09 10:20   ` Burton, Ross
@ 2014-09-09 13:03     ` Theodore Ts'o
  2014-09-09 13:09       ` Burton, Ross
  0 siblings, 1 reply; 5+ messages in thread
From: Theodore Ts'o @ 2014-09-09 13:03 UTC (permalink / raw)
  To: Burton, Ross; +Cc: linux-ext4

On Tue, Sep 09, 2014 at 11:20:34AM +0100, Burton, Ross wrote:
> 
> Thanks Ted.
> 
> I see that you merged before 1.42.12 was released but this didn't make
> 1.42.12.  Will it be in 1.42.13, or is it waiting for a 1.43.0
> release?

It's on the master branch, which means it's waiting on 1.43.  It's
very likely that 1.42.12 will be last maint branch release, and that
1.43.0 will be releasing relatively soon with inline data and metadata
checksum support.  There are a number of patches still in the review
queue and some additional testing we need to do before we can release
1.43, though.

Cheers,

						- Ted

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

* Re: [V4] misc: copy extended attributes in populate_fs
  2014-09-09 13:03     ` Theodore Ts'o
@ 2014-09-09 13:09       ` Burton, Ross
  0 siblings, 0 replies; 5+ messages in thread
From: Burton, Ross @ 2014-09-09 13:09 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: linux-ext4

On 9 September 2014 14:03, Theodore Ts'o <tytso@mit.edu> wrote:
> It's on the master branch, which means it's waiting on 1.43.  It's
> very likely that 1.42.12 will be last maint branch release, and that
> 1.43.0 will be releasing relatively soon with inline data and metadata
> checksum support.  There are a number of patches still in the review
> queue and some additional testing we need to do before we can release
> 1.43, though.

Thanks, it's good to understand this.

Cheers,
Ross

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

end of thread, other threads:[~2014-09-09 13:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-10 16:44 [PATCH][V4] misc: copy extended attributes in populate_fs Ross Burton
2014-07-28  1:29 ` [V4] " Theodore Ts'o
2014-09-09 10:20   ` Burton, Ross
2014-09-09 13:03     ` Theodore Ts'o
2014-09-09 13:09       ` Burton, Ross

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox