INITRAMFS: Add option to preserve mtime from INITRAMFS cpio images
PATCH 1/1 INITRAMFS: Add option to preserve mtime from INITRAMFS cpio images
From: Nye Liu <[email protected]>
When unpacking the cpio into the initramfs, mtimes are not preserved by default. This patch adds an INITRAMFS_PRESERVE_MTIME option that allows mtimes stored in the cpio image to be used when constructing the initramfs. For embedded applications that run exclusively out of the initramfs, this is invaluable.
---
init/initramfs.c +97 -0
@@ -7,6 +7,12 @@#include <linux/string.h> #include <linux/syscalls.h> +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +#include <linux/utime.h> +#include <linux/namei.h> +#include <linux/list.h> +#endif +static __initdata char *message;static void __init error (char *x) {
@@ -72,6 +78,38 @@ static void __init free_hash(void) } } +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +static __initdata LIST_HEAD (dir_list); +struct dir_entry { +struct list_head list; +char *name; +struct utimbuf mtime; +}; + +static void __init dir_add (const char *name,struct utimbuf mtime) +{ +struct dir_entry *de =kmalloc (sizeof (struct dir_entry ),GFP_KERNEL ); +INIT_LIST_HEAD (&de->list); + de->name =kstrdup (name,GFP_KERNEL ); + de->mtime = mtime; +list_add (&de->list, &dir_list); +} + +static void __init dir_utime (void ) +{ +struct list_head *e, *tmp; +list_for_each_safe (e, tmp, &dir_list) { + struct dir_entry *de = list_entry(e, struct dir_entry, list); +list_del (e); +sys_utime (de->name, &de->mtime); +kfree (de->name); +kfree (de); + } +} + +static __initdata struct utimbuf mtime; +#endif +/* cpio header parsing */ static __initdata unsigned long ino, major, minor, nlink;
@@ -97,6 +135,9 @@ static void __init parse_header(char *s) uid = parsed[2 ]; gid = parsed[3 ]; nlink = parsed[4 ]; +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME + mtime.actime = mtime.modtime = parsed[5 ]; +#endif body_len = parsed[6 ]; major = parsed[7 ]; minor = parsed[8 ];
@@ -130,6 +171,10 @@ static inline void __init eat(unsigned n) count -= n; } +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +static __initdata char *vcollected; +#endif +static __initdata char *collected;static __initdata int remains;static __initdata char *collect;
@@ -271,6 +316,9 @@ static int __init do_name(void)if (wfd >=0 ) {sys_fchown (wfd, uid, gid);sys_fchmod (wfd, mode); +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME + vcollected =kstrdup (collected,GFP_KERNEL ); +#endif state = CopyFile; } }
@@ -278,12 +326,18 @@ static int __init do_name(void)sys_mkdir (collected, mode);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +dir_add (collected, mtime); +#endif }else if (S_ISBLK (mode) ||S_ISCHR (mode) ||S_ISFIFO (mode) ||S_ISSOCK (mode)) {if (maybe_link () ==0 ) {sys_mknod (collected, mode, rdev);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +sys_utime (collected, &mtime); +#endif } }return 0 ;
@@ -294,6 +348,10 @@ static int __init do_copy(void)if (count >= body_len) {sys_write (wfd, victim, body_len);sys_close (wfd); +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +sys_utime (vcollected, &mtime); +kfree (vcollected); +#endif eat (body_len); state = SkipIt;return 0 ;
@@ -305,12 +363,48 @@ static int __init do_copy(void) } } +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +static long __init sys_lutime (char __user * filename, +struct utimbuf __user * times) +{ +int error; +struct path path; +struct inode * inode; +struct iattr newattrs; + + error =user_lpath (filename, &path); +if (error)return error; + + inode = path.dentry->d_inode; + + newattrs.ia_valid =ATTR_CTIME |ATTR_MTIME |ATTR_ATIME ; + error =0 ; +if (IS_APPEND (inode) ||IS_IMMUTABLE (inode)) + goto pput_and_out; + + newattrs.ia_atime.tv_sec = times->actime; + newattrs.ia_atime.tv_nsec =0 ; + newattrs.ia_mtime.tv_sec = times->modtime; + newattrs.ia_mtime.tv_nsec =0 ; + newattrs.ia_valid |=ATTR_ATIME_SET |ATTR_MTIME_SET ; +mutex_lock (&inode->i_mutex); + error =notify_change (path.dentry, &newattrs); +mutex_unlock (&inode->i_mutex); +pput_and_out: +path_put (&path); +return error; +} +#endif +static int __init do_symlink (void ) { collected[N_ALIGN (name_len) + body_len] ='\0' ;clean_path (collected,0 );sys_symlink (collected +N_ALIGN (name_len), collected);sys_lchown (collected, uid, gid); +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +sys_lutime (collected, &mtime); +#endif state = SkipIt; next_state = Reset;return 0 ;
@@ -466,6 +560,9 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) buf += inptr; len -= inptr; } +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +dir_utime (); +#endif kfree (window);kfree (name_buf);kfree (symlink_buf);
usr/Kconfig +10 -0
@@ -44,3 +44,13 @@ config INITRAMFS_ROOT_GID owned by group root in the initial ramdisk image. If you are not sure, leave it set to "0". + +config INITRAMFS_PRESERVE_MTIME + bool "Preserve mtimes from INITRAMFS image" + depends on BLK_DEV_INITRD + default n + help + Preserve mtimes (last modified times) for all items stored in the + initramfs image. + + If you are not sure, leave it set to "N"
Quoted 17 lines · On Tue, 5 Aug 2008 12:52:32 -0700 Nye Liu <[email protected]> wrote:
From: Nye Liu <[email protected]>
When unpacking the cpio into the initramfs, mtimes are not preserved by default. This patch adds an
INITRAMFS_PRESERVE_MTIMEoption that allows mtimes stored in the cpio image to be used when constructing the initramfs. For embedded applications that run exclusively out of the initramfs, this is invaluable.Signed-off-by Nye Liu <[email protected]>---
init/initramfs.c +0
-0
init/initramfs.c line 14
Quoted 8 lines
init/initramfs.c +5
-0@@ -7,6 +7,12 @@#include <linux/string.h> #include <linux/syscalls.h> +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +#include <linux/utime.h> +#include <linux/namei.h> +#include <linux/list.h> +#endif
It would be better to do it unconditionally if possible - remove the config option and all the ifdefs.
Quoted 8 lines
init/initramfs.c +1
-0static __initdata char *message;static void __init error (char *x) {@@ -72,6 +78,38 @@ static void __init free_hash(void) } } +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME
init/initramfs.c static void __init free_hash(void) · line 91
Quoted 10 lines
init/initramfs.c +10
-0+static __initdata LIST_HEAD (dir_list); +struct dir_entry { +struct list_head list; +char *name; +struct utimbuf mtime; +}; + +static void __init dir_add (const char *name,struct utimbuf mtime) +{ +struct dir_entry *de =kmalloc (sizeof (struct dir_entry ),GFP_KERNEL );
kmalloc() can fail..
Quoted 86 lines
init/initramfs.c +41
-0+INIT_LIST_HEAD (&de->list); + de->name =kstrdup (name,GFP_KERNEL ); + de->mtime = mtime; +list_add (&de->list, &dir_list); +} + +static void __init dir_utime (void ) +{ +struct list_head *e, *tmp; +list_for_each_safe (e, tmp, &dir_list) { + struct dir_entry *de = list_entry(e, struct dir_entry, list); +list_del (e); +sys_utime (de->name, &de->mtime); +kfree (de->name); +kfree (de); + } +} + +static __initdata struct utimbuf mtime; +#endif +/* cpio header parsing */ static __initdata unsigned long ino, major, minor, nlink;@@ -97,6 +135,9 @@ static void __init parse_header(char *s) uid = parsed[2 ]; gid = parsed[3 ]; nlink = parsed[4 ]; +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME + mtime.actime = mtime.modtime = parsed[5 ]; +#endif body_len = parsed[6 ]; major = parsed[7 ]; minor = parsed[8 ];@@ -130,6 +171,10 @@ static inline void __init eat(unsigned n) count -= n; } +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +static __initdata char *vcollected; +#endif +static __initdata char *collected;static __initdata int remains;static __initdata char *collect;@@ -271,6 +316,9 @@ static int __init do_name(void)if (wfd >=0 ) {sys_fchown (wfd, uid, gid);sys_fchmod (wfd, mode); +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME + vcollected =kstrdup (collected,GFP_KERNEL ); +#endif state = CopyFile; } }@@ -278,12 +326,18 @@ static int __init do_name(void)sys_mkdir (collected, mode);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +dir_add (collected, mtime); +#endif }else if (S_ISBLK (mode) ||S_ISCHR (mode) ||S_ISFIFO (mode) ||S_ISSOCK (mode)) {if (maybe_link () ==0 ) {sys_mknod (collected, mode, rdev);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +sys_utime (collected, &mtime); +#endif } }return 0 ;@@ -294,6 +348,10 @@ static int __init do_copy(void)if (count >= body_len) {sys_write (wfd, victim, body_len);sys_close (wfd); +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +sys_utime (vcollected, &mtime); +kfree (vcollected); +#endif eat (body_len); state = SkipIt;return 0 ;
init/initramfs.c static int __init do_copy(void) · line 368
Quoted 6 lines
init/initramfs.c +3
-0@@ -305,12 +363,48 @@ static int __init do_copy(void) } } +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +static long __init sys_lutime (char __user * filename, +struct utimbuf __user * times)
Please avoid using the sys_ namespace. That is for system calls.
Please pass the patch through scripts/checkpatch.pl and review the report.
Quoted 18 lines
init/initramfs.c +18
-0+{ +int error; +struct path path; +struct inode * inode; +struct iattr newattrs; + + error =user_lpath (filename, &path); +if (error)return error; + + inode = path.dentry->d_inode; + + newattrs.ia_valid =ATTR_CTIME |ATTR_MTIME |ATTR_ATIME ; + error =0 ; +if (IS_APPEND (inode) ||IS_IMMUTABLE (inode)) + goto pput_and_out; + + newattrs.ia_atime.tv_sec = times->actime; + newattrs.ia_atime.tv_nsec =0 ;
init/initramfs.c static int __init do_copy(void) · line 396
Quoted 10 lines
init/initramfs.c +10
-0+ newattrs.ia_mtime.tv_sec = times->modtime; + newattrs.ia_mtime.tv_nsec =0 ; + newattrs.ia_valid |=ATTR_ATIME_SET |ATTR_MTIME_SET ; +mutex_lock (&inode->i_mutex); + error =notify_change (path.dentry, &newattrs); +mutex_unlock (&inode->i_mutex); +pput_and_out: +path_put (&path); +return error; +}
How does this differ from sys_utime()?
Can this use do_utimes()?
Quoted 42 lines
init/initramfs.c +8
-0+#endif +static int __init do_symlink (void ) { collected[N_ALIGN (name_len) + body_len] ='\0' ;clean_path (collected,0 );sys_symlink (collected +N_ALIGN (name_len), collected);sys_lchown (collected, uid, gid); +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +sys_lutime (collected, &mtime); +#endif state = SkipIt; next_state = Reset;return 0 ;@@ -466,6 +560,9 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) buf += inptr; len -= inptr; } +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +dir_utime (); +#endif kfree (window);kfree (name_buf);kfree (symlink_buf);usr/Kconfig +10
-0@@ -44,3 +44,13 @@ config INITRAMFS_ROOT_GID owned by group root in the initial ramdisk image. If you are not sure, leave it set to "0". + +config INITRAMFS_PRESERVE_MTIME + bool "Preserve mtimes from INITRAMFS image" + depends on BLK_DEV_INITRD + default n + help + Preserve mtimes (last modified times) for all items stored in the + initramfs image. + + If you are not sure, leave it set to "N"
PATCH 1/1 INITRAMFS: Add option to preserve mtime from INITRAMFS cpio images
In reply to Nye LiuResubmission of initramfs preserve mtime patch following Andrew Morton's suggestions.
From: Nye Liu <[email protected]>
When unpacking the cpio into the initramfs, mtimes are not preserved by default. This patch adds an INITRAMFS_PRESERVE_MTIME option that allows mtimes stored in the cpio image to be used when constructing the initramfs. For embedded applications that run exclusively out of the initramfs, this is invaluable.
init/initramfs.c +55 -0
@@ -6,6 +6,7 @@#include <linux/delay.h> #include <linux/string.h> #include <linux/syscalls.h> +#include <linux/utime.h> static __initdata char *message;static void __init error (char *x)
@@ -72,6 +73,38 @@ static void __init free_hash(void) } } +static __initdata LIST_HEAD (dir_list); +struct dir_entry { +struct list_head list; +char *name; +struct utimbuf mtime; +}; + +static void __init dir_add (const char *name,struct utimbuf mtime) +{ +struct dir_entry *de =kmalloc (sizeof (struct dir_entry ),GFP_KERNEL ); +if (!de) +panic ("can't allocate dir_entry buffer" ); +INIT_LIST_HEAD (&de->list); + de->name =kstrdup (name,GFP_KERNEL ); + de->mtime = mtime; +list_add (&de->list, &dir_list); +} + +static void __init dir_utime (void ) +{ +struct list_head *e, *tmp; +list_for_each_safe (e, tmp, &dir_list) { + struct dir_entry *de = list_entry(e, struct dir_entry, list); +list_del (e); +sys_utime (de->name, &de->mtime); +kfree (de->name); +kfree (de); + } +} + +static __initdata struct utimbuf mtime; +/* cpio header parsing */ static __initdata unsigned long ino, major, minor, nlink;
@@ -97,6 +130,7 @@ static void __init parse_header(char *s) uid = parsed[2 ]; gid = parsed[3 ]; nlink = parsed[4 ]; + mtime.actime = mtime.modtime = parsed[5 ]; body_len = parsed[6 ]; major = parsed[7 ]; minor = parsed[8 ];
@@ -130,6 +164,7 @@ static inline void __init eat(unsigned n) count -= n; } +static __initdata char *vcollected;static __initdata char *collected;static __initdata int remains;static __initdata char *collect;
@@ -271,6 +306,7 @@ static int __init do_name(void)if (wfd >=0 ) {sys_fchown (wfd, uid, gid);sys_fchmod (wfd, mode); + vcollected =kstrdup (collected,GFP_KERNEL ); state = CopyFile; } }
@@ -278,12 +314,14 @@ static int __init do_name(void)sys_mkdir (collected, mode);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +dir_add (collected, mtime); }else if (S_ISBLK (mode) ||S_ISCHR (mode) ||S_ISFIFO (mode) ||S_ISSOCK (mode)) {if (maybe_link () ==0 ) {sys_mknod (collected, mode, rdev);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +sys_utime (collected, &mtime); } }return 0 ;
@@ -294,6 +332,8 @@ static int __init do_copy(void)if (count >= body_len) {sys_write (wfd, victim, body_len);sys_close (wfd); +sys_utime (vcollected, &mtime); +kfree (vcollected);eat (body_len); state = SkipIt;return 0 ;
@@ -305,12 +345,26 @@ static int __init do_copy(void) } } +static long __init do_lutime (char __user *filename, +struct utimbuf __user *times) +{ +struct timespec t[2 ]; + + t[0 ].tv_sec = times->actime; + t[0 ].tv_nsec =0 ; + t[1 ].tv_sec = times->modtime; + t[1 ].tv_nsec =0 ; + +return do_utimes (AT_FDCWD , filename, t,AT_SYMLINK_NOFOLLOW ); +} +static int __init do_symlink (void ) { collected[N_ALIGN (name_len) + body_len] ='\0' ;clean_path (collected,0 );sys_symlink (collected +N_ALIGN (name_len), collected);sys_lchown (collected, uid, gid); +do_lutime (collected, &mtime); state = SkipIt; next_state = Reset;return 0 ;
@@ -466,6 +520,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) buf += inptr; len -= inptr; } +dir_utime ();kfree (window);kfree (name_buf);kfree (symlink_buf);
Quoted 2 lines · On Wed, 3 Sep 2008 13:29:38 -0700 Nye Liu <[email protected]> wrote:
Resubmission of initramfs preserve mtime patch following Andrew Morton's suggestions.
It's nice to provide some sort of accounting for the reviewer's individual comments. But in this case I only had three or fopur and I see how they were addressed.
Quoted 7 lines
From: Nye Liu <[email protected]>
When unpacking the cpio into the initramfs, mtimes are not preserved by default. This patch adds an
INITRAMFS_PRESERVE_MTIMEoption that allows mtimes stored in the cpio image to be used when constructing the initramfs. For embedded applications that run exclusively out of the initramfs, this is invaluable.
Why is it "invlauable". Please explain this value in full detail - it's the whole reason for merging the patch!
Quoted 33 lines
Signed-off-by Nye Liu <[email protected]>init/initramfs.c +16
-0@@ -6,6 +6,7 @@#include <linux/delay.h> #include <linux/string.h> #include <linux/syscalls.h> +#include <linux/utime.h> static __initdata char *message;static void __init error (char *x)@@ -72,6 +73,38 @@ static void __init free_hash(void) } } +static __initdata LIST_HEAD (dir_list); +struct dir_entry { +struct list_head list; +char *name; +struct utimbuf mtime; +}; + +static void __init dir_add (const char *name,struct utimbuf mtime) +{ +struct dir_entry *de =kmalloc (sizeof (struct dir_entry ),GFP_KERNEL ); +if (!de) +panic ("can't allocate dir_entry buffer" ); +INIT_LIST_HEAD (&de->list); + de->name =kstrdup (name,GFP_KERNEL ); + de->mtime = mtime;
init/initramfs.c static void __init free_hash(void) · line 100
Quoted 10 lines
init/initramfs.c +10
-0+list_add (&de->list, &dir_list); +} + +static void __init dir_utime (void ) +{ +struct list_head *e, *tmp; +list_for_each_safe (e, tmp, &dir_list) { + struct dir_entry *de = list_entry(e, struct dir_entry, list); +list_del (e); +sys_utime (de->name, &de->mtime);
gargh. Why does this work? It's normally a big fail to pass a kernel address into a system call. I guess we're running under KERNEL_DS here and getname() and strncpy_from_user() did the right thing.
On what CPU architecture was this tested?
Wouldn't it be simpler to put a timespec into struct dir_entry then go direct to do_utimes() here?
Quoted 50 lines
init/initramfs.c +12
-0+kfree (de->name); +kfree (de); + } +} + +static __initdata struct utimbuf mtime; +/* cpio header parsing */ static __initdata unsigned long ino, major, minor, nlink;@@ -97,6 +130,7 @@ static void __init parse_header(char *s) uid = parsed[2 ]; gid = parsed[3 ]; nlink = parsed[4 ]; + mtime.actime = mtime.modtime = parsed[5 ]; body_len = parsed[6 ]; major = parsed[7 ]; minor = parsed[8 ];@@ -130,6 +164,7 @@ static inline void __init eat(unsigned n) count -= n; } +static __initdata char *vcollected;static __initdata char *collected;static __initdata int remains;static __initdata char *collect;@@ -271,6 +306,7 @@ static int __init do_name(void)if (wfd >=0 ) {sys_fchown (wfd, uid, gid);sys_fchmod (wfd, mode); + vcollected =kstrdup (collected,GFP_KERNEL ); state = CopyFile; } }@@ -278,12 +314,14 @@ static int __init do_name(void)sys_mkdir (collected, mode);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +dir_add (collected, mtime); }else if (S_ISBLK (mode) ||S_ISCHR (mode) ||S_ISFIFO (mode) ||S_ISSOCK (mode)) {if (maybe_link () ==0 ) {sys_mknod (collected, mode, rdev);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +sys_utime (collected, &mtime); } }return 0 ;
init/initramfs.c static int __init do_copy(void) · line 335
Quoted 4 lines
init/initramfs.c +1
-0@@ -294,6 +332,8 @@ static int __init do_copy(void)if (count >= body_len) {sys_write (wfd, victim, body_len);sys_close (wfd); +sys_utime (vcollected, &mtime);
and here?
Quoted 32 lines
init/initramfs.c +15
-0+kfree (vcollected);eat (body_len); state = SkipIt;return 0 ;@@ -305,12 +345,26 @@ static int __init do_copy(void) } } +static long __init do_lutime (char __user *filename, +struct utimbuf __user *times) +{ +struct timespec t[2 ]; + + t[0 ].tv_sec = times->actime; + t[0 ].tv_nsec =0 ; + t[1 ].tv_sec = times->modtime; + t[1 ].tv_nsec =0 ; + +return do_utimes (AT_FDCWD , filename, t,AT_SYMLINK_NOFOLLOW ); +} +static int __init do_symlink (void ) { collected[N_ALIGN (name_len) + body_len] ='\0' ;clean_path (collected,0 );sys_symlink (collected +N_ALIGN (name_len), collected);sys_lchown (collected, uid, gid); +do_lutime (collected, &mtime); state = SkipIt; next_state = Reset;return 0 ;
init/initramfs.c static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) · line 523
Quoted 4 lines
init/initramfs.c +1
-0@@ -466,6 +520,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) buf += inptr; len -= inptr; } +dir_utime ();
Perhaps this is the simplest implementation - I didn't check the fine details. What's your thinking here?
Quoted 10 lines · Andrew Morton
Quoted 7 lines
From: Nye Liu <[email protected]>
When unpacking the cpio into the initramfs, mtimes are not preserved by default. This patch adds an
INITRAMFS_PRESERVE_MTIMEoption that allows mtimes stored in the cpio image to be used when constructing the initramfs. For embedded applications that run exclusively out of the initramfs, this is invaluable.Why is it "invlauable". Please explain this value in full detail - it's the whole reason for merging the patch!
When building embedded application initramfs images, its nice to know when the files were actually created during the build process - that makes it easier to see what files were modified when so we can compare the files that are being used on the image with the files used during the build process. This might help (for example) to determine if the target system has all the updated files you expect to see w/o having to check MD5s etc.
In our environment, the whole system runs off the initramfs partition, and seeing the modified times of the shared libraries (for example) helps us find bugs that may have been introduced by the build system incorrectly propogating outdated shared libraries into the image.
Similarly, many of the initializion/configuration files in /etc might be dynamically built by the build system, and knowing when they were modified helps us sanity check whether the target system has the "latest" files etc.
Finally, we might use last modified times to determine whether a hot fix should be applied or not to the running ramfs.
Nye
Quoted 150 lines
Quoted 34 lines
Signed-off-by Nye Liu <[email protected]>init/initramfs.c +16
-0@@ -6,6 +6,7 @@#include <linux/delay.h> #include <linux/string.h> #include <linux/syscalls.h> +#include <linux/utime.h> static __initdata char *message;static void __init error (char *x)@@ -72,6 +73,38 @@ static void __init free_hash(void) } } +static __initdata LIST_HEAD (dir_list); +struct dir_entry { +struct list_head list; +char *name; +struct utimbuf mtime; +}; + +static void __init dir_add (const char *name,struct utimbuf mtime) +{ +struct dir_entry *de =kmalloc (sizeof (struct dir_entry ),GFP_KERNEL ); +if (!de) +panic ("can't allocate dir_entry buffer" ); +INIT_LIST_HEAD (&de->list); + de->name =kstrdup (name,GFP_KERNEL ); + de->mtime = mtime;init/initramfs.c static void __init free_hash(void) · line 100
Quoted 10 lines
init/initramfs.c +10
-0+list_add (&de->list, &dir_list); +} + +static void __init dir_utime (void ) +{ +struct list_head *e, *tmp; +list_for_each_safe (e, tmp, &dir_list) { + struct dir_entry *de = list_entry(e, struct dir_entry, list); +list_del (e); +sys_utime (de->name, &de->mtime);gargh. Why does this work? It's normally a big fail to pass a kernel address into a system call. I guess we're running under
KERNEL_DShere andgetname()andstrncpy_from_user()did the right thing.On what CPU architecture was this tested?
Wouldn't it be simpler to put a timespec into struct
dir_entrythen go direct todo_utimes()here?Quoted 50 lines
init/initramfs.c +12
-0+kfree (de->name); +kfree (de); + } +} + +static __initdata struct utimbuf mtime; +/* cpio header parsing */ static __initdata unsigned long ino, major, minor, nlink;@@ -97,6 +130,7 @@ static void __init parse_header(char *s) uid = parsed[2 ]; gid = parsed[3 ]; nlink = parsed[4 ]; + mtime.actime = mtime.modtime = parsed[5 ]; body_len = parsed[6 ]; major = parsed[7 ]; minor = parsed[8 ];@@ -130,6 +164,7 @@ static inline void __init eat(unsigned n) count -= n; } +static __initdata char *vcollected;static __initdata char *collected;static __initdata int remains;static __initdata char *collect;@@ -271,6 +306,7 @@ static int __init do_name(void)if (wfd >=0 ) {sys_fchown (wfd, uid, gid);sys_fchmod (wfd, mode); + vcollected =kstrdup (collected,GFP_KERNEL ); state = CopyFile; } }@@ -278,12 +314,14 @@ static int __init do_name(void)sys_mkdir (collected, mode);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +dir_add (collected, mtime); }else if (S_ISBLK (mode) ||S_ISCHR (mode) ||S_ISFIFO (mode) ||S_ISSOCK (mode)) {if (maybe_link () ==0 ) {sys_mknod (collected, mode, rdev);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +sys_utime (collected, &mtime); } }return 0 ;init/initramfs.c static int __init do_copy(void) · line 335
Quoted 4 lines
init/initramfs.c +1
-0@@ -294,6 +332,8 @@ static int __init do_copy(void)if (count >= body_len) {sys_write (wfd, victim, body_len);sys_close (wfd); +sys_utime (vcollected, &mtime);and here?
Quoted 32 lines
init/initramfs.c +15
-0+kfree (vcollected);eat (body_len); state = SkipIt;return 0 ;@@ -305,12 +345,26 @@ static int __init do_copy(void) } } +static long __init do_lutime (char __user *filename, +struct utimbuf __user *times) +{ +struct timespec t[2 ]; + + t[0 ].tv_sec = times->actime; + t[0 ].tv_nsec =0 ; + t[1 ].tv_sec = times->modtime; + t[1 ].tv_nsec =0 ; + +return do_utimes (AT_FDCWD , filename, t,AT_SYMLINK_NOFOLLOW ); +} +static int __init do_symlink (void ) { collected[N_ALIGN (name_len) + body_len] ='\0' ;clean_path (collected,0 );sys_symlink (collected +N_ALIGN (name_len), collected);sys_lchown (collected, uid, gid); +do_lutime (collected, &mtime); state = SkipIt; next_state = Reset;return 0 ;init/initramfs.c static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) · line 523
Quoted 4 lines
init/initramfs.c +1
-0@@ -466,6 +520,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) buf += inptr; len -= inptr; } +dir_utime ();Perhaps this is the simplest implementation - I didn't check the fine details. What's your thinking here?
Signature · 7 lines
Nye Liu [email protected] (818) 772-6235x248 (818) 772-0576 fax "Who would be stupid enough to quote a fictitious character?" -- Don Quixote
Quoted 25 lines · On Wed, 3 Sep 2008 15:31:14 -0700 Nye Liu <[email protected]> wrote:
Quoted 10 lines · Andrew Morton
Quoted 7 lines
From: Nye Liu <[email protected]>
When unpacking the cpio into the initramfs, mtimes are not preserved by default. This patch adds an
INITRAMFS_PRESERVE_MTIMEoption that allows mtimes stored in the cpio image to be used when constructing the initramfs. For embedded applications that run exclusively out of the initramfs, this is invaluable.Why is it "invlauable". Please explain this value in full detail - it's the whole reason for merging the patch!
When building embedded application initramfs images, its nice to know when the files were actually created during the build process - that makes it easier to see what files were modified when so we can compare the files that are being used on the image with the files used during the build process. This might help (for example) to determine if the target system has all the updated files you expect to see w/o having to check MD5s etc.
In our environment, the whole system runs off the initramfs partition, and seeing the modified times of the shared libraries (for example) helps us find bugs that may have been introduced by the build system incorrectly propogating outdated shared libraries into the image.
Quoted 8 lines
Similarly, many of the initializion/configuration files in /etc might be dynamically built by the build system, and knowing when they were modified helps us sanity check whether the target system has the "latest" files etc.
Finally, we might use last modified times to determine whether a hot fix should be applied or not to the running ramfs.
Thanks, I updated the changelog.
Quoted 9 lines
Quoted 9 lines
gargh. Why does this work? It's normally a big fail to pass a kernel address into a system call. I guess we're running under
KERNEL_DShere andgetname()andstrncpy_from_user()did the right thing.On what CPU architecture was this tested?
Wouldn't it be simpler to put a timespec into struct
dir_entrythen go direct todo_utimes()here?
Did you see this stuff?
2008/9/4 Nye Liu <[email protected]>:
Quoted 12 lines · Andrew Morton
Quoted 10 lines
Quoted 7 lines
From: Nye Liu <[email protected]>
When unpacking the cpio into the initramfs, mtimes are not preserved by default. This patch adds an
INITRAMFS_PRESERVE_MTIMEoption that allows mtimes stored in the cpio image to be used when constructing the initramfs. For embedded applications that run exclusively out of the initramfs, this is invaluable.Why is it "invlauable". Please explain this value in full detail - it's the whole reason for merging the patch!
Quoted 7 lines
When building embedded application initramfs images, its nice to know when the files were actually created during the build process - that makes it easier to see what files were modified when so we can compare the files that are being used on the image with the files used during the build process. This might help (for example) to determine if the target system has all the updated files you expect to see w/o having to check MD5s etc.
Hm.
"Invaluable" != "nice to know".
What worries me is that this code is executed at boot time (when populating the ramfs).
For embedded systems a fast boot time is often important.
I admit that the net effect of this on boot time is marginal (but some might consider having mtime a marginal benefit), and 100 cents also make a dollar, so my suggestion would be to either reject this patch or make it optional (e.g. depending on some debug config flag).
Best regards, Frans.
Quoted 36 lines · Frans Meulenbroeks
2008/9/4 Nye Liu <[email protected]>:
Quoted 13 lines · Andrew Morton
Quoted 12 lines
Quoted 9 lines
From: Nye Liu <[email protected]>
When unpacking the cpio into the initramfs, mtimes are not preserved by default. This patch adds an
INITRAMFS_PRESERVE_MTIMEoption that allows mtimes stored in the cpio image to be used when constructing the initramfs. For embedded applications that run exclusively out of the initramfs, this is invaluable.Why is it "invlauable". Please explain this value in full detail - it's the whole reason for merging the patch!
Quoted 8 lines
When building embedded application initramfs images, its nice to know when the files were actually created during the build process - that makes it easier to see what files were modified when so we can compare the files that are being used on the image with the files used during the build process. This might help (for example) to determine if the target system has all the updated files you expect to see w/o having to check MD5s etc.
Hm.
"Invaluable" != "nice to know".
What worries me is that this code is executed at boot time (when populating the ramfs).
For embedded systems a fast boot time is often important.
I admit that the net effect of this on boot time is marginal (but some might consider having mtime a marginal benefit), and 100 cents also make a dollar, so my suggestion would be to either reject this patch or make it optional (e.g. depending on some debug config flag).
Quoted 2 lines
Best regards, Frans.
An earlier rev patch made it optional. I can resubmit of course.
Quoted 1 line · Frans Meulenbroeks
"Invaluable" != "nice to know".
Well, I guess it's as "invaluable" for embedded systems running on initramfs as mtime on regular filesystems in case of normal systems.
Is mtime on ext3 "invaluable" or just "nice to know"?
Quoted 4 lines
I admit that the net effect of this on boot time is marginal (but some might consider having mtime a marginal benefit), and 100 cents also make a dollar, so my suggestion would be to either reject this patch or make it optional (e.g. depending on some debug config flag).
It depends on how marginal is it. If it makes unpacking 1% slower I can see no need for being optional. 10% - maybe it should?
Signature · 1 line
Krzysztof Halasa
Quoted 40 lines · Andrew Morton
On Wed, 3 Sep 2008 13:29:38 -0700
Quoted 39 lines
Signed-off-by Nye Liu <[email protected]>init/initramfs.c +22
-0@@ -6,6 +6,7 @@#include <linux/delay.h> #include <linux/string.h> #include <linux/syscalls.h> +#include <linux/utime.h> static __initdata char *message;static void __init error (char *x)@@ -72,6 +73,38 @@ static void __init free_hash(void) } } +static __initdata LIST_HEAD (dir_list); +struct dir_entry { +struct list_head list; +char *name; +struct utimbuf mtime; +}; + +static void __init dir_add (const char *name,struct utimbuf mtime) +{ +struct dir_entry *de =kmalloc (sizeof (struct dir_entry ),GFP_KERNEL ); +if (!de) +panic ("can't allocate dir_entry buffer" ); +INIT_LIST_HEAD (&de->list); + de->name =kstrdup (name,GFP_KERNEL ); + de->mtime = mtime; +list_add (&de->list, &dir_list); +} + +static void __init dir_utime (void ) +{ +struct list_head *e, *tmp;
Quoted 8 lines
init/initramfs.c static void __init free_hash(void) · line 100
Quoted 4 lines
init/initramfs.c +4
-0+list_for_each_safe (e, tmp, &dir_list) { + struct dir_entry *de = list_entry(e, struct dir_entry, list); +list_del (e); +sys_utime (de->name, &de->mtime);gargh. Why does this work? It's normally a big fail to pass a kernel address into a system call. I guess we're running under
KERNEL_DShere andgetname()andstrncpy_from_user()did the right thing.
Possibly, i was not aware of that limitation :( I'll look into it
Quoted 1 line
On what CPU architecture was this tested?
ppc and powerpc
Quoted 2 lines
Wouldn't it be simpler to put a timespec into struct
dir_entrythen go direct todo_utimes()here?
No, if i understand your question correctly. I have to do the mtime modifications in two passes (see last comment below)
Quoted 49 lines
Quoted 49 lines
init/initramfs.c +12
-0+kfree (de->name); +kfree (de); + } +} + +static __initdata struct utimbuf mtime; +/* cpio header parsing */ static __initdata unsigned long ino, major, minor, nlink;@@ -97,6 +130,7 @@ static void __init parse_header(char *s) uid = parsed[2 ]; gid = parsed[3 ]; nlink = parsed[4 ]; + mtime.actime = mtime.modtime = parsed[5 ]; body_len = parsed[6 ]; major = parsed[7 ]; minor = parsed[8 ];@@ -130,6 +164,7 @@ static inline void __init eat(unsigned n) count -= n; } +static __initdata char *vcollected;static __initdata char *collected;static __initdata int remains;static __initdata char *collect;@@ -271,6 +306,7 @@ static int __init do_name(void)if (wfd >=0 ) {sys_fchown (wfd, uid, gid);sys_fchmod (wfd, mode); + vcollected =kstrdup (collected,GFP_KERNEL ); state = CopyFile; } }@@ -278,12 +314,14 @@ static int __init do_name(void)sys_mkdir (collected, mode);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +dir_add (collected, mtime); }else if (S_ISBLK (mode) ||S_ISCHR (mode) ||S_ISFIFO (mode) ||S_ISSOCK (mode)) {if (maybe_link () ==0 ) {sys_mknod (collected, mode, rdev);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +sys_utime (collected, &mtime); } }
Quoted 8 lines
init/initramfs.c static int __init do_copy(void) · line 335
Quoted 6 lines
init/initramfs.c +1
-0return 0 ;@@ -294,6 +332,8 @@ static int __init do_copy(void)if (count >= body_len) {sys_write (wfd, victim, body_len);sys_close (wfd); +sys_utime (vcollected, &mtime);and here?
see below regarding two passes.
Quoted 31 lines
Quoted 31 lines
init/initramfs.c +15
-0+kfree (vcollected);eat (body_len); state = SkipIt;return 0 ;@@ -305,12 +345,26 @@ static int __init do_copy(void) } } +static long __init do_lutime (char __user *filename, +struct utimbuf __user *times) +{ +struct timespec t[2 ]; + + t[0 ].tv_sec = times->actime; + t[0 ].tv_nsec =0 ; + t[1 ].tv_sec = times->modtime; + t[1 ].tv_nsec =0 ; + +return do_utimes (AT_FDCWD , filename, t,AT_SYMLINK_NOFOLLOW ); +} +static int __init do_symlink (void ) { collected[N_ALIGN (name_len) + body_len] ='\0' ;clean_path (collected,0 );sys_symlink (collected +N_ALIGN (name_len), collected);sys_lchown (collected, uid, gid); +do_lutime (collected, &mtime); state = SkipIt; next_state = Reset;return 0 ;
Quoted 9 lines
init/initramfs.c static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) · line 523
Quoted 5 lines
init/initramfs.c +1
-0@@ -466,6 +520,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) buf += inptr; len -= inptr; } +dir_utime ();Perhaps this is the simplest implementation - I didn't check the fine details. What's your thinking here?
The main problem is that i need to save off the entire list for later processing of the directory mtimes... if i process the directory mtimes in the same pass as the file/link mtimes, touching the directory inode when creating/modifying the file/links updates the directory mtime, and overwrites whatever mtime i set the directory to when i created it.
The only solution is to do a two pass, which is why the list is necessary. If there is a better way, i did not find it :(
It could be that i misunderstood your question though :)
Quoted 24 lines · On Wed, 3 Sep 2008 15:41:31 -0700 Nye Liu <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
init/initramfs.c +1
-0collected[N_ALIGN (name_len) + body_len] ='\0' ;clean_path (collected,0 );sys_symlink (collected +N_ALIGN (name_len), collected);sys_lchown (collected, uid, gid); +do_lutime (collected, &mtime); state = SkipIt; next_state = Reset;return 0 ;Quoted 9 lines
init/initramfs.c static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) · line 523
Quoted 5 lines
init/initramfs.c +1
-0@@ -466,6 +520,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) buf += inptr; len -= inptr; } +dir_utime ();Perhaps this is the simplest implementation - I didn't check the fine details. What's your thinking here?
The main problem is that i need to save off the entire list for later processing of the directory mtimes... if i process the directory mtimes in the same pass as the file/link mtimes, touching the directory inode when creating/modifying the file/links updates the directory mtime, and overwrites whatever mtime i set the directory to when i created it.
Quoted 4 lines
The only solution is to do a two pass, which is why the list is necessary. If there is a better way, i did not find it :(
It could be that i misunderstood your question though :)
I'm wondering whether this code need to use `struct utimbuf' at all. Or at least, as much as it does. utimbuf is more a userspace-facing thing whereas in-kernel timespecs and timevals are more common.
The code as you have it does a fair few conversions into utimbuf format (both directly and via the existing functions which it calls). Would it be simpler if it dealt in terms of timespecs?
Quoted 32 lines · Andrew Morton
Quoted 24 lines · On Wed, 3 Sep 2008 15:41:31 -0700 Nye Liu <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
init/initramfs.c +1
-0collected[N_ALIGN (name_len) + body_len] ='\0' ;clean_path (collected,0 );sys_symlink (collected +N_ALIGN (name_len), collected);sys_lchown (collected, uid, gid); +do_lutime (collected, &mtime); state = SkipIt; next_state = Reset;return 0 ;Quoted 9 lines
init/initramfs.c static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) · line 523
Quoted 5 lines
init/initramfs.c +1
-0@@ -466,6 +520,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) buf += inptr; len -= inptr; } +dir_utime ();Perhaps this is the simplest implementation - I didn't check the fine details. What's your thinking here?
The main problem is that i need to save off the entire list for later processing of the directory mtimes... if i process the directory mtimes in the same pass as the file/link mtimes, touching the directory inode when creating/modifying the file/links updates the directory mtime, and overwrites whatever mtime i set the directory to when i created it.
Quoted 4 lines
The only solution is to do a two pass, which is why the list is necessary. If there is a better way, i did not find it :(
It could be that i misunderstood your question though :)
Quoted 8 lines
I'm wondering whether this code need to use `struct utimbuf' at all. Or at least, as much as it does. utimbuf is more a userspace-facing thing whereas in-kernel timespecs and timevals are more common.
The code as you have it does a fair few conversions into utimbuf format (both directly and via the existing functions which it calls). Would it be simpler if it dealt in terms of timespecs?
It could be. Heck, it would be even simpler to just use a single time_t (since cpio doesn't have timespecs OR seperate atime/mtimes):
static __initdata LIST_HEAD(dir_list);
struct dir_entry {
struct list_head list;
char *name;
time_t mtime;
};then make a simple wrapper for sys_utime() to convert the time_t into a the utimbuf:
static void __init do_utime(char *name, time_t mtime)
{
struct utimbuf time;
time.actime=time.modtime=mtime;
sys_utime(name, &time);
}I can try it that way and resubmit. Gimme a bit to compose a patch
ALSO it disturbs me about the alloc problem you mentioned, especially since i did NOT TEST on anything but our embedded (ppc/powerpc) target.
Signature · 7 lines
Nye Liu [email protected] (818) 772-6235x248 (818) 772-0576 fax "Who would be stupid enough to quote a fictitious character?" -- Don Quixote
Quoted 32 lines · Andrew Morton
Quoted 24 lines · On Wed, 3 Sep 2008 15:41:31 -0700 Nye Liu <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
(quoted diff) +1
-0collected[N_ALIGN(name_len) + body_len] = '\0'; clean_path(collected, 0); sys_symlink(collected + N_ALIGN(name_len), collected); sys_lchown(collected, uid, gid); + do_lutime(collected, &mtime); state = SkipIt; next_state = Reset; return 0;Quoted 9 lines
Review static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) · line 523
Quoted 5 lines
(quoted diff) +1
-0@@ -466,6 +520,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) buf += inptr; len -= inptr; } + dir_utime();Perhaps this is the simplest implementation - I didn't check the fine details. What's your thinking here?
The main problem is that i need to save off the entire list for later processing of the directory mtimes... if i process the directory mtimes in the same pass as the file/link mtimes, touching the directory inode when creating/modifying the file/links updates the directory mtime, and overwrites whatever mtime i set the directory to when i created it.
Quoted 4 lines
The only solution is to do a two pass, which is why the list is necessary. If there is a better way, i did not find it :(
It could be that i misunderstood your question though :)
Quoted 8 lines
I'm wondering whether this code need to use `struct utimbuf' at all. Or at least, as much as it does. utimbuf is more a userspace-facing thing whereas in-kernel timespecs and timevals are more common.
The code as you have it does a fair few conversions into utimbuf format (both directly and via the existing functions which it calls). Would it be simpler if it dealt in terms of timespecs?
maybe something like this:
init/initramfs.c +62 -0
@@ -6,6 +6,7 @@#include <linux/delay.h> #include <linux/string.h> #include <linux/syscalls.h> +#include <linux/utime.h> static __initdata char *message;static void __init error (char *x)
@@ -72,6 +73,45 @@ static void __init free_hash(void) } } +static __initdata LIST_HEAD (dir_list); +struct dir_entry { +struct list_head list; +char *name; +time_t mtime; +}; + +static void __init dir_add (const char *name,time_t mtime) +{ +struct dir_entry *de =kmalloc (sizeof (struct dir_entry ),GFP_KERNEL ); +if (!de) +panic ("can't allocate dir_entry buffer" ); +INIT_LIST_HEAD (&de->list); + de->name =kstrdup (name,GFP_KERNEL ); + de->mtime = mtime; +list_add (&de->list, &dir_list); +} + +static void __init do_utime (char *name,time_t mtime) +{ +struct utimbuf time; + time.actime=time.modtime=mtime; +sys_utime (name, &time); +} + +static void __init dir_utime (void ) +{ +struct list_head *e, *tmp; +list_for_each_safe (e, tmp, &dir_list) { + struct dir_entry *de = list_entry(e, struct dir_entry, list); +list_del (e); +do_utime (de->name, de->mtime); +kfree (de->name); +kfree (de); + } +} + +static __initdata time_t mtime; +/* cpio header parsing */ static __initdata unsigned long ino, major, minor, nlink;
@@ -97,6 +137,7 @@ static void __init parse_header(char *s) uid = parsed[2 ]; gid = parsed[3 ]; nlink = parsed[4 ]; + mtime = parsed[5 ]; body_len = parsed[6 ]; major = parsed[7 ]; minor = parsed[8 ];
@@ -130,6 +171,7 @@ static inline void __init eat(unsigned n) count -= n; } +static __initdata char *vcollected;static __initdata char *collected;static __initdata int remains;static __initdata char *collect;
@@ -271,6 +313,7 @@ static int __init do_name(void)if (wfd >=0 ) {sys_fchown (wfd, uid, gid);sys_fchmod (wfd, mode); + vcollected =kstrdup (collected,GFP_KERNEL ); state = CopyFile; } }
@@ -278,12 +321,14 @@ static int __init do_name(void)sys_mkdir (collected, mode);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +dir_add (collected, mtime); }else if (S_ISBLK (mode) ||S_ISCHR (mode) ||S_ISFIFO (mode) ||S_ISSOCK (mode)) {if (maybe_link () ==0 ) {sys_mknod (collected, mode, rdev);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +do_utime (collected, mtime); } }return 0 ;
@@ -294,6 +339,8 @@ static int __init do_copy(void)if (count >= body_len) {sys_write (wfd, victim, body_len);sys_close (wfd); +do_utime (vcollected, mtime); +kfree (vcollected);eat (body_len); state = SkipIt;return 0 ;
@@ -305,12 +352,26 @@ static int __init do_copy(void) } } +static long __init do_lutime (char __user *filename, +time_t mtime) +{ +struct timespec t[2 ]; + + t[0 ].tv_sec = mtime; + t[0 ].tv_nsec =0 ; + t[1 ].tv_sec = mtime; + t[1 ].tv_nsec =0 ; + +return do_utimes (AT_FDCWD , filename, t,AT_SYMLINK_NOFOLLOW ); +} +static int __init do_symlink (void ) { collected[N_ALIGN (name_len) + body_len] ='\0' ;clean_path (collected,0 );sys_symlink (collected +N_ALIGN (name_len), collected);sys_lchown (collected, uid, gid); +do_lutime (collected, mtime); state = SkipIt; next_state = Reset;return 0 ;
@@ -466,6 +527,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) buf += inptr; len -= inptr; } +dir_utime ();kfree (window);kfree (name_buf);kfree (symlink_buf);
Signature · 7 lines
Nye Liu [email protected] (818) 772-6235x248 (818) 772-0576 fax "Who would be stupid enough to quote a fictitious character?" -- Don Quixote
Quoted 32 lines · Andrew Morton
Quoted 24 lines · On Wed, 3 Sep 2008 15:41:31 -0700 Nye Liu <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
(quoted diff) +1
-0collected[N_ALIGN(name_len) + body_len] = '\0'; clean_path(collected, 0); sys_symlink(collected + N_ALIGN(name_len), collected); sys_lchown(collected, uid, gid); + do_lutime(collected, &mtime); state = SkipIt; next_state = Reset; return 0;Quoted 9 lines
Review static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) · line 523
Quoted 5 lines
(quoted diff) +1
-0@@ -466,6 +520,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) buf += inptr; len -= inptr; } + dir_utime();Perhaps this is the simplest implementation - I didn't check the fine details. What's your thinking here?
The main problem is that i need to save off the entire list for later processing of the directory mtimes... if i process the directory mtimes in the same pass as the file/link mtimes, touching the directory inode when creating/modifying the file/links updates the directory mtime, and overwrites whatever mtime i set the directory to when i created it.
Quoted 4 lines
The only solution is to do a two pass, which is why the list is necessary. If there is a better way, i did not find it :(
It could be that i misunderstood your question though :)
Quoted 8 lines
I'm wondering whether this code need to use `struct utimbuf' at all. Or at least, as much as it does. utimbuf is more a userspace-facing thing whereas in-kernel timespecs and timevals are more common.
The code as you have it does a fair few conversions into utimbuf format (both directly and via the existing functions which it calls). Would it be simpler if it dealt in terms of timespecs?
or maybe this, this one ONLY using do_utimes() and a single wrapper to convert the time_t
init/initramfs.c +55 -0
@@ -6,6 +6,7 @@#include <linux/delay.h> #include <linux/string.h> #include <linux/syscalls.h> +#include <linux/utime.h> static __initdata char *message;static void __init error (char *x)
@@ -72,6 +73,51 @@ static void __init free_hash(void) } } +static long __init do_utime (char __user *filename, +time_t mtime) +{ +struct timespec t[2 ]; + + t[0 ].tv_sec = mtime; + t[0 ].tv_nsec =0 ; + t[1 ].tv_sec = mtime; + t[1 ].tv_nsec =0 ; + +return do_utimes (AT_FDCWD , filename, t,AT_SYMLINK_NOFOLLOW ); +} + +static __initdata LIST_HEAD (dir_list); +struct dir_entry { +struct list_head list; +char *name; +time_t mtime; +}; + +static void __init dir_add (const char *name,time_t mtime) +{ +struct dir_entry *de =kmalloc (sizeof (struct dir_entry ),GFP_KERNEL ); +if (!de) +panic ("can't allocate dir_entry buffer" ); +INIT_LIST_HEAD (&de->list); + de->name =kstrdup (name,GFP_KERNEL ); + de->mtime = mtime; +list_add (&de->list, &dir_list); +} + +static void __init dir_utime (void ) +{ +struct list_head *e, *tmp; +list_for_each_safe (e, tmp, &dir_list) { + struct dir_entry *de = list_entry(e, struct dir_entry, list); +list_del (e); +do_utime (de->name, de->mtime); +kfree (de->name); +kfree (de); + } +} + +static __initdata time_t mtime; +/* cpio header parsing */ static __initdata unsigned long ino, major, minor, nlink;
@@ -97,6 +143,7 @@ static void __init parse_header(char *s) uid = parsed[2 ]; gid = parsed[3 ]; nlink = parsed[4 ]; + mtime = parsed[5 ]; body_len = parsed[6 ]; major = parsed[7 ]; minor = parsed[8 ];
@@ -130,6 +177,7 @@ static inline void __init eat(unsigned n) count -= n; } +static __initdata char *vcollected;static __initdata char *collected;static __initdata int remains;static __initdata char *collect;
@@ -271,6 +319,7 @@ static int __init do_name(void)if (wfd >=0 ) {sys_fchown (wfd, uid, gid);sys_fchmod (wfd, mode); + vcollected =kstrdup (collected,GFP_KERNEL ); state = CopyFile; } }
@@ -278,12 +327,14 @@ static int __init do_name(void)sys_mkdir (collected, mode);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +dir_add (collected, mtime); }else if (S_ISBLK (mode) ||S_ISCHR (mode) ||S_ISFIFO (mode) ||S_ISSOCK (mode)) {if (maybe_link () ==0 ) {sys_mknod (collected, mode, rdev);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +do_utime (collected, mtime); } }return 0 ;
@@ -294,6 +345,8 @@ static int __init do_copy(void)if (count >= body_len) {sys_write (wfd, victim, body_len);sys_close (wfd); +do_utime (vcollected, mtime); +kfree (vcollected);eat (body_len); state = SkipIt;return 0 ;
@@ -311,6 +364,7 @@ static int __init do_symlink(void)clean_path (collected,0 );sys_symlink (collected +N_ALIGN (name_len), collected);sys_lchown (collected, uid, gid); +do_utime (collected, mtime); state = SkipIt; next_state = Reset;return 0 ;
@@ -466,6 +520,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) buf += inptr; len -= inptr; } +dir_utime ();kfree (window);kfree (name_buf);kfree (symlink_buf);
Signature · 7 lines
Nye Liu [email protected] (818) 772-6235x248 (818) 772-0576 fax "Who would be stupid enough to quote a fictitious character?" -- Don Quixote
Quoted 37 lines · On Wed, 3 Sep 2008 16:04:30 -0700 Nye Liu <[email protected]> wrote:
Quoted 36 lines · Andrew Morton
Quoted 24 lines · On Wed, 3 Sep 2008 15:41:31 -0700 Nye Liu <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
init/initramfs.c +1
-0collected[N_ALIGN (name_len) + body_len] ='\0' ;clean_path (collected,0 );sys_symlink (collected +N_ALIGN (name_len), collected);sys_lchown (collected, uid, gid); +do_lutime (collected, &mtime); state = SkipIt; next_state = Reset;return 0 ;Quoted 9 lines
init/initramfs.c static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) · line 523
Quoted 5 lines
init/initramfs.c +1
-0@@ -466,6 +520,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) buf += inptr; len -= inptr; } +dir_utime ();Perhaps this is the simplest implementation - I didn't check the fine details. What's your thinking here?
The main problem is that i need to save off the entire list for later processing of the directory mtimes... if i process the directory mtimes in the same pass as the file/link mtimes, touching the directory inode when creating/modifying the file/links updates the directory mtime, and overwrites whatever mtime i set the directory to when i created it.
Quoted 4 lines
The only solution is to do a two pass, which is why the list is necessary. If there is a better way, i did not find it :(
It could be that i misunderstood your question though :)
I'm wondering whether this code need to use `struct utimbuf' at all. Or at least, as much as it does. utimbuf is more a userspace-facing thing whereas in-kernel timespecs and timevals are more common.
Quoted 7 lines
Quoted 4 lines
The code as you have it does a fair few conversions into utimbuf format (both directly and via the existing functions which it calls). Would it be simpler if it dealt in terms of timespecs?
or maybe this, this one ONLY using
do_utimes()and a single wrapper to convert thetime_t
Getting better ;)
Quoted 13 lines
init/initramfs.c +1
-0@@ -6,6 +6,7 @@#include <linux/delay.h> #include <linux/string.h> #include <linux/syscalls.h> +#include <linux/utime.h> static __initdata char *message;static void __init error (char *x)
init/initramfs.c static void __init free_hash(void) · line 77
Quoted 5 lines
init/initramfs.c +2
-0@@ -72,6 +73,51 @@ static void __init free_hash(void) } } +static long __init do_utime (char __user *filename, +time_t mtime)
Please avoid wrapping things which don't need it.
init/initramfs.c static void __init free_hash(void) · line 84
Quoted 7 lines
init/initramfs.c +7
-0+{ +struct timespec t[2 ]; + + t[0 ].tv_sec = mtime; + t[0 ].tv_nsec =0 ; + t[1 ].tv_sec = mtime; + t[1 ].tv_nsec =0 ;
Sub-second information is lost. It'd be nice to preserve it if we're going to do this thing.
Quoted 7 lines
init/initramfs.c +7
-0+return do_utimes (AT_FDCWD , filename, t,AT_SYMLINK_NOFOLLOW ); +} + +static __initdata LIST_HEAD (dir_list); +struct dir_entry { +struct list_head list; +char *name;
init/initramfs.c static void __init free_hash(void) · line 102
Quoted 10 lines
init/initramfs.c +10
-0+time_t mtime; +}; + +static void __init dir_add (const char *name,time_t mtime) +{ +struct dir_entry *de =kmalloc (sizeof (struct dir_entry ),GFP_KERNEL ); +if (!de) +panic ("can't allocate dir_entry buffer" ); +INIT_LIST_HEAD (&de->list); + de->name =kstrdup (name,GFP_KERNEL );
Alas, kstrdup() can fail too.
It's all a bit silly checking for kmalloc() failures at this stage in the boot process. Particularly if all we can do is panic - we might as well blunder ahead and dereference the NULL pointer, which gives us just as much info as the panic. And there's not much point in handling the allocation and continuing the boot, because the system obviously won't be booting.
So it'd be understandable to just omit the error-checking here, despite my earlier mentioning of its absence ;)
init/initramfs.c static void __init free_hash(void) · line 111
Quoted 9 lines
init/initramfs.c +9
-0+ de->mtime = mtime; +list_add (&de->list, &dir_list); +} + +static void __init dir_utime (void ) +{ +struct list_head *e, *tmp; +list_for_each_safe (e, tmp, &dir_list) { + struct dir_entry *de = list_entry(e, struct dir_entry, list);
could use list_for_each_entry_safe() here.
Quoted 6 lines
init/initramfs.c +6
-0+list_del (e); +do_utime (de->name, de->mtime); +kfree (de->name); +kfree (de); + } +}
Quoted 66 lines · Andrew Morton
Quoted 37 lines · On Wed, 3 Sep 2008 16:04:30 -0700 Nye Liu <[email protected]> wrote:
Quoted 36 lines · Andrew Morton
Quoted 24 lines · On Wed, 3 Sep 2008 15:41:31 -0700 Nye Liu <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
init/initramfs.c +1
-0collected[N_ALIGN (name_len) + body_len] ='\0' ;clean_path (collected,0 );sys_symlink (collected +N_ALIGN (name_len), collected);sys_lchown (collected, uid, gid); +do_lutime (collected, &mtime); state = SkipIt; next_state = Reset;return 0 ;Quoted 9 lines
init/initramfs.c static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) · line 523
Quoted 5 lines
init/initramfs.c +1
-0@@ -466,6 +520,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) buf += inptr; len -= inptr; } +dir_utime ();Perhaps this is the simplest implementation - I didn't check the fine details. What's your thinking here?
The main problem is that i need to save off the entire list for later processing of the directory mtimes... if i process the directory mtimes in the same pass as the file/link mtimes, touching the directory inode when creating/modifying the file/links updates the directory mtime, and overwrites whatever mtime i set the directory to when i created it.
Quoted 4 lines
The only solution is to do a two pass, which is why the list is necessary. If there is a better way, i did not find it :(
It could be that i misunderstood your question though :)
I'm wondering whether this code need to use `struct utimbuf' at all. Or at least, as much as it does. utimbuf is more a userspace-facing thing whereas in-kernel timespecs and timevals are more common.
Quoted 7 lines
Quoted 4 lines
The code as you have it does a fair few conversions into utimbuf format (both directly and via the existing functions which it calls). Would it be simpler if it dealt in terms of timespecs?
or maybe this, this one ONLY using
do_utimes()and a single wrapper to convert thetime_tGetting better ;)
Quoted 16 lines
init/initramfs.c +1
-0@@ -6,6 +6,7 @@#include <linux/delay.h> #include <linux/string.h> #include <linux/syscalls.h> +#include <linux/utime.h> static __initdata char *message;static void __init error (char *x)@@ -72,6 +73,51 @@ static void __init free_hash(void) } }
Quoted 4 lines
init/initramfs.c static void __init free_hash(void) · line 77
Quoted 2 lines
init/initramfs.c +2
-0+static long __init do_utime (char __user *filename, +time_t mtime)Please avoid wrapping things which don't need it.
Hard to avoid, unless you want me composing the following every place i'm currently calling do_utime():
Quoted 10 lines
init/initramfs.c static void __init free_hash(void) · line 84
Quoted 7 lines
init/initramfs.c +7
-0+{ +struct timespec t[2 ]; + + t[0 ].tv_sec = mtime; + t[0 ].tv_nsec =0 ; + t[1 ].tv_sec = mtime; + t[1 ].tv_nsec =0 ;Sub-second information is lost. It'd be nice to preserve it if we're going to do this thing.
Can't! cpio isn't that smart!
Quoted 28 lines
Quoted 8 lines
init/initramfs.c +7
-0+return do_utimes (AT_FDCWD , filename, t,AT_SYMLINK_NOFOLLOW ); +} + +static __initdata LIST_HEAD (dir_list); +struct dir_entry { +struct list_head list; +char *name;init/initramfs.c static void __init free_hash(void) · line 102
Quoted 10 lines
init/initramfs.c +10
-0+time_t mtime; +}; + +static void __init dir_add (const char *name,time_t mtime) +{ +struct dir_entry *de =kmalloc (sizeof (struct dir_entry ),GFP_KERNEL ); +if (!de) +panic ("can't allocate dir_entry buffer" ); +INIT_LIST_HEAD (&de->list); + de->name =kstrdup (name,GFP_KERNEL );Alas,
kstrdup()can fail too.It's all a bit silly checking for
kmalloc()failures at this stage in the boot process. Particularly if all we can do is panic - we might as well blunder ahead and dereference the NULL pointer, which gives us just as much info as the panic. And there's not much point in handling the allocation and continuing the boot, because the system obviously won't be booting.
Quoted 2 lines
So it'd be understandable to just omit the error-checking here, despite my earlier mentioning of its absence ;)
LOL. You're the boss.
Quoted 12 lines
init/initramfs.c static void __init free_hash(void) · line 111
Quoted 10 lines
init/initramfs.c +9
-0+ de->mtime = mtime; +list_add (&de->list, &dir_list); +} + +static void __init dir_utime (void ) +{ +struct list_head *e, *tmp; +list_for_each_safe (e, tmp, &dir_list) { + struct dir_entry *de = list_entry(e, struct dir_entry, list);could use
list_for_each_entry_safe()here.
static void __init dir_utime(void)
{
struct dir_entry *de, *tmp;
list_for_each_entry_safe(de, tmp, &dir_list, list) {
list_del(de);
do_utime(de->name, de->mtime);
kfree(de->name);
kfree(de);
}
}something like that? I assume list_del(de) is fine.
Quoted 7 lines
Quoted 6 lines
init/initramfs.c +6
-0+list_del (e); +do_utime (de->name, de->mtime); +kfree (de->name); +kfree (de); + } +}
Signature · 7 lines
Nye Liu [email protected] (818) 772-6235x248 (818) 772-0576 fax "Who would be stupid enough to quote a fictitious character?" -- Don Quixote
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 INITRAMFS: Preserve mtime from INITRAMFS cpio images
one last shot :)
supercedes initramfs-add-option-to-preserve-mtime-from-initramfs-cpio-images.patch
init/initramfs.c +53 -0
@@ -6,6 +6,7 @@#include <linux/delay.h> #include <linux/string.h> #include <linux/syscalls.h> +#include <linux/utime.h> static __initdata char *message;static void __init error (char *x)
@@ -72,6 +73,49 @@ static void __init free_hash(void) } } +static long __init do_utime (char __user *filename,time_t mtime) +{ +struct timespec t[2 ]; + + t[0 ].tv_sec = mtime; + t[0 ].tv_nsec =0 ; + t[1 ].tv_sec = mtime; + t[1 ].tv_nsec =0 ; + +return do_utimes (AT_FDCWD , filename, t,AT_SYMLINK_NOFOLLOW ); +} + +static __initdata LIST_HEAD (dir_list); +struct dir_entry { +struct list_head list; +char *name; +time_t mtime; +}; + +static void __init dir_add (const char *name,time_t mtime) +{ +struct dir_entry *de =kmalloc (sizeof (struct dir_entry ),GFP_KERNEL ); +if (!de) +panic ("can't allocate dir_entry buffer" ); +INIT_LIST_HEAD (&de->list); + de->name =kstrdup (name,GFP_KERNEL ); + de->mtime = mtime; +list_add (&de->list, &dir_list); +} + +static void __init dir_utime (void ) +{ +struct dir_entry *de, *tmp; +list_for_each_entry_safe (de, tmp, &dir_list, list) { +list_del (&de->list); +do_utime (de->name, de->mtime); +kfree (de->name); +kfree (de); + } +} + +static __initdata time_t mtime; +/* cpio header parsing */ static __initdata unsigned long ino, major, minor, nlink;
@@ -97,6 +141,7 @@ static void __init parse_header(char *s) uid = parsed[2 ]; gid = parsed[3 ]; nlink = parsed[4 ]; + mtime = parsed[5 ]; body_len = parsed[6 ]; major = parsed[7 ]; minor = parsed[8 ];
@@ -130,6 +175,7 @@ static inline void __init eat(unsigned n) count -= n; } +static __initdata char *vcollected;static __initdata char *collected;static __initdata int remains;static __initdata char *collect;
@@ -271,6 +317,7 @@ static int __init do_name(void)if (wfd >=0 ) {sys_fchown (wfd, uid, gid);sys_fchmod (wfd, mode); + vcollected =kstrdup (collected,GFP_KERNEL ); state = CopyFile; } }
@@ -278,12 +325,14 @@ static int __init do_name(void)sys_mkdir (collected, mode);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +dir_add (collected, mtime); }else if (S_ISBLK (mode) ||S_ISCHR (mode) ||S_ISFIFO (mode) ||S_ISSOCK (mode)) {if (maybe_link () ==0 ) {sys_mknod (collected, mode, rdev);sys_chown (collected, uid, gid);sys_chmod (collected, mode); +do_utime (collected, mtime); } }return 0 ;
@@ -294,6 +343,8 @@ static int __init do_copy(void)if (count >= body_len) {sys_write (wfd, victim, body_len);sys_close (wfd); +do_utime (vcollected, mtime); +kfree (vcollected);eat (body_len); state = SkipIt;return 0 ;
@@ -311,6 +362,7 @@ static int __init do_symlink(void)clean_path (collected,0 );sys_symlink (collected +N_ALIGN (name_len), collected);sys_lchown (collected, uid, gid); +do_utime (collected, mtime); state = SkipIt; next_state = Reset;return 0 ;
@@ -466,6 +518,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) buf += inptr; len -= inptr; } +dir_utime ();kfree (window);kfree (name_buf);kfree (symlink_buf);
Quoted 16 lines · Andrew Morton
Quoted 7 lines · On Wed, 3 Sep 2008 16:30:56 -0700 Nye Liu <[email protected]> wrote:
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+static long __init do_utime(char __user *filename, + time_t mtime)Please avoid wrapping things which don't need it.
Hard to avoid, unless you want me composing the following every place i'm currently calling
do_utime():I meant "wordwrapping":
static long
__initdo_utime(char __user *filename, time_t mtime)easily fits in 80-cols.
Signature · 7 lines
Nye Liu [email protected] (818) 772-6235x248 (818) 772-0576 fax "Who would be stupid enough to quote a fictitious character?" -- Don Quixote