Reduced dependecies for /root on lvm
Hi all,
i found, that the vgscan and vgchange commands, needed for activation of volumes, depend on shared libc and ld-loader in the initrd. Even if these two are linked static, there remains a dependecie, due to a system() call of the 'rm -rf' command. I added a little routine to do this task to liblvm, removed the system(rm...) calls and changed the tools/Makefile to link vgscan.static and vgchange.static.
I did'n change lvmcreate_initrd 'cause i still do this by hand (sorry ;-)).
It works for me, my initrd is much smaller now (stripped the executables ;-)), there are less pof's (point-of-failure) when trying to install with root on a lv.
Comments and bugreports are welcome.
Ciao
Klaus
Signature · 5 lines
Klaus Strebel [email protected] EIGNER + PARTNER AG - The Engineering Warehouse Company - <http://www.ep-ag.com> -----------------------------------------------------------------------
tools/Makefile +16 -10
@@ -29,14 +29,14 @@ # # uncomment next line and comment out XLINKER # if you like binding with static LVM library -## LIBS = $(TOP)/tools/lib/liblvm.a +STATLIBS = $(TOP)/tools/lib/liblvm.a XLINKER = -Xlinker -rpath $(TOP)/tools/lib -Xlinker -rpath /lib -Xlinker -rpath /usr/lib -llvm include ../make.tmpl include tools_and_lib.make.tmpl LDFLAGS = $(LIBS) -L$(TOP)/tools/lib $(XLINKER) -ALL = $(ALL_SOURCES:.c=) +ALL = $(ALL_SOURCES:.c=) vgscan.static vgchange.static ALL_RM = $(ALL) $(ALL_OBJECTS) ALL_SCRIPTS = lvmcreate_initrd
@@ -44,34 +44,40 @@ $(ALL_OBJECTS): Makefile lib/liblvm.h lvm_user.h +vgscan.static: vgscan.o $(STATLIBS) + $(CC) -static $(LDFLAGS) -o $@ vgscan.o $(STATLIBS) + +vgchange.static: vgchange.o $(STATLIBS) + $(CC) -static $(LDFLAGS) -o $@ vgchange.o $(STATLIBS) + all_this: $(ALL_OBJECTS) $(ALL) $(ALL_SOURCES) $(ALL_HEADERS) $(OTHER_DEP) $(LIBS) @echo "" @echo "Done Tools parts" @echo "" -strip: $(ALL_TARGETS) +strip: $(ALL_TARGETS) vgscan.static vgchange.static @echo @echo "Stripping all executables..." @echo - @strip $(ALL_TARGETS) >/dev/null 2>&1 + @strip $(ALL_TARGETS) vgscan.static vgchange.static >/dev/null 2>&1 list: $(ALL_TARGETS) @ls -l $(ALL_TARGETS) l: list -install-bin: $(ALL_TARGETS) $(ALL_SCRIPTS) - @echo "*** Installing $(ALL_TARGETS) $(ALL_SCRIPTS) in $(BINDIR) ***" - @for f in $(ALL_TARGETS) $(ALL_SCRIPTS); \ +install-bin: $(ALL_TARGETS) $(ALL_SCRIPTS) vgscan.static vgchange.static + @echo "*** Installing $(ALL_TARGETS) $(ALL_SCRIPTS) vgscan.static vgchange.static in $(BINDIR) ***" + @for f in $(ALL_TARGETS) $(ALL_SCRIPTS) vgscan.static vgchange.static; \ do \ rm -f $(BINDIR)/$$f; \ install -o root -g root -m 555 -s $$f $(BINDIR)/$$f; \ done -remove-bin: $(ALL_TARGETS) $(ALL_SCRIPTS) - @echo "*** Removing $(ALL_TARGETS) $(ALL_SCRIPTS) from $(BINDIR) ***" - @for f in $(ALL_TARGETS) $(ALL_SCRIPTS); \ +remove-bin: $(ALL_TARGETS) $(ALL_SCRIPTS) vgscan.static vgchange.static + @echo "*** Removing $(ALL_TARGETS) $(ALL_SCRIPTS) vgscan.static vgchange.static from $(BINDIR) ***" + @for f in $(ALL_TARGETS) $(ALL_SCRIPTS) vgscan.static vgchange.static; \ do \ rm -f $(BINDIR)/$$f; \ done
tools/lib/liblvm.h +1 -1
@@ -421,7 +421,7 @@int lvm_tab_vg_check_exist (char *,vg_t **);int lvm_tab_get_free_blk_dev (kdev_t **);char **lvm_tab_vg_check_exist_all_vg (void ); - +int lvm_rm_rf (char *);/* return codes */ #define LVM_VG_CFGBACKUP_NO_DIFF 100
tools/lib/lvm_rm_rf.c +59 -0
59 lines not on this page · raw message
tools/lib/lvm_tab_vg_check_exist_all_vg.c +7 -4
@@ -91,10 +91,13 @@#ifdef DEBUG debug ("lvm_tab_vg_check_exist_all_vg -- LEAVING with ret: %d\n" , ret);#endif -if ( ret <0 || size <2 ) { -free ( data); -if ( vg_name_ptr !=NULL )free ( vg_name_ptr); -if ( vg_name_ptr_sav !=NULL )free ( vg_name_ptr_sav); +if ( ret <0 || size <2 ) { +if ( data !=NULL ) { +free ( data); + data =NULL ; + } +if ( vg_name_ptr !=NULL )free ( vg_name_ptr); +else if ( vg_name_ptr_sav !=NULL )free ( vg_name_ptr_sav); }return vg_name_ptr;
tools/lib/lvm_tab_vg_remove.c +2 -2
@@ -83,8 +83,8 @@ }if ( ( ret =lvm_tab_write ( data, size)) ==0 ) { -sprintf ( command,"rm -f %s/%s%c" ,LVMTAB_DIR , vg_name,0 ); - ret =system ( command); +sprintf ( command,"%s/%s%c" ,LVMTAB_DIR , vg_name,0 ); + ret =lvm_rm_rf ( command); } } }
tools/lib/vg_create_dir_and_group.c +2 -2
@@ -48,8 +48,8 @@if ( vg ==NULL ||vg_check_name ( vg->vg_name) <0 )return -LVM_EPARAM ; -sprintf ( name,"rm -fr " LVM_DIR_PREFIX "%s%c" , vg->vg_name,0 ); -system ( name); +sprintf ( name,"%s%s%c" ,LVM_DIR_PREFIX , vg->vg_name,0 ); +lvm_rm_rf ( name);mkdir (LVM_DIR_PREFIX ,0555 );sprintf ( name,LVM_DIR_PREFIX "%s%c" , vg->vg_name,0 );if (mkdir ( name,0555 ) ==-1 ) ret = -LVM_EVG_CREATE_DIR_AND_GROUP_MKDIR ;
tools/lib/vg_remove_dir_and_group_and_nodes.c +2 -2
@@ -36,12 +36,12 @@if ( vg_name ==NULL ||vg_check_name ( vg_name) <0 )return -LVM_EPARAM ;/* remove the volume group directory */ -sprintf ( system_buffer,"rm -fr " LVM_DIR_PREFIX "%s%c" , vg_name,0 ); +sprintf ( system_buffer,"%s%s%c" ,LVM_DIR_PREFIX , vg_name,0 );#ifdef DEBUG debug ("vg_remove_dir_and_group_and_nodes -- LEAVING\n" );#endif -return system ( system_buffer); +return (lvm_rm_rf (system_buffer)); }
tools/vgscan.c +4 -2
@@ -185,8 +185,10 @@if ( opt_v >0 )printf ("%s -- removing \"%s\" and \"%s\"\n" , cmd,LVMTAB ,LVMTAB_DIR ); -sprintf ( command,"rm -fr %s %s%c" ,LVMTAB ,LVMTAB_DIR ,0 ); -system ( command); +sprintf ( command,"%s%c" ,LVMTAB ,0 ); +lvm_rm_rf ( command); +sprintf ( command,"%s%c" ,LVMTAB_DIR ,0 ); +lvm_rm_rf ( command);printf ("%s -- reading all physical volumes (this may take a while...)\n" , cmd);
Quoted 1 line · Klaus Strebel
Comments and bugreports are welcome.
I don't think it will work with sub directories. dp->d_type is normally DT_UNKNOWN on all Linux systems, libc5 dirent does not even have that field. Please use a fstat.
-Andi
Quoted 7 lines · Andi Kleen
Quoted 1 line · Klaus Strebel
Comments and bugreports are welcome.
I don't think it will work with sub directories.
dp->d_typeis normallyDT_UNKNOWNon all Linux systems, libc5 dirent does not even have that field. Please use a fstat.
Well, i think your're right. Made i tiny small test proggy. But the new lvm_rm_rf.c does it (now tested with several dirs including subdirs and files and s.o.).
Ciao
Klaus
Signature · 5 lines
Klaus Strebel [email protected] EIGNER + PARTNER AG - The Engineering Warehouse Company - <http://www.ep-ag.com> -----------------------------------------------------------------------