gfs2-utils: Remove 'die' calls from mount_gfs2_meta
PATCH 1/1 gfs2-utils: Remove 'die' calls from mount_gfs2_meta
This patch removes the calls to 'die' from mount_gfs2_meta and adds error reporting: It now returns -1 with errno set. All callers of this function are updated to check for errors.
The static function lock_for_admin gets similar treatment as mount_gfs2_meta is its only caller.
Signed-off-by Andrew Price <[email protected]>
--- gfs2/libgfs2/libgfs2.h | 2 +- gfs2/libgfs2/misc.c | 20 ++++++++++---------- gfs2/mkfs/main_grow.c | 6 +++++- gfs2/mkfs/main_jadd.c | 6 +++++- gfs2/quota/check.c | 12 ++++++++++-- gfs2/quota/main.c | 24 ++++++++++++++++++++---- gfs2/tool/df.c | 6 +++++- gfs2/tool/misc.c | 7 ++++++- 8 files changed, 62 insertions(+), 21 deletions(-)
gfs2/libgfs2/libgfs2.h +1 -1
@@ -628,7 +628,7 @@ extern void compute_constants(struct gfs2_sbd *sdp);extern int find_gfs2_meta (struct gfs2_sbd *sdp);extern int dir_exists (const char *dir);extern int check_for_gfs2 (struct gfs2_sbd *sdp); -extern void mount_gfs2_meta (struct gfs2_sbd *sdp); +extern int mount_gfs2_meta (struct gfs2_sbd *sdp);extern void cleanup_metafs (struct gfs2_sbd *sdp);extern char *find_debugfs_mount (void );extern char *mp2fsname (char *mp);
gfs2/libgfs2/misc.c +10 -10
@@ -148,7 +148,7 @@ int check_for_gfs2(struct gfs2_sbd *sdp)return -1 ; } -static void lock_for_admin (struct gfs2_sbd *sdp) +static int lock_for_admin (struct gfs2_sbd *sdp) {int error;
@@ -157,18 +157,18 @@ static void lock_for_admin(struct gfs2_sbd *sdp) sdp->metafs_fd =open (sdp->metafs_path,O_RDONLY |O_NOFOLLOW );if (sdp->metafs_fd <0 ) -die ("can't open %s: %s\n" , - sdp->metafs_path,strerror (errno)); +return -1 ; error =flock (sdp->metafs_fd,LOCK_EX );if (error) -die ("can't flock %s: %s\n" , sdp->metafs_path,strerror (errno)); +return -1 ;if (sdp->debug)printf ("Got it.\n" ); +return 0 ; } -void mount_gfs2_meta (struct gfs2_sbd *sdp) +int mount_gfs2_meta (struct gfs2_sbd *sdp) {int ret;
@@ -176,16 +176,16 @@ void mount_gfs2_meta(struct gfs2_sbd *sdp)snprintf (sdp->metafs_path,PATH_MAX -1 ,"/tmp/.gfs2meta.XXXXXX" );if (!mkdtemp (sdp->metafs_path)) -die ("Couldn't create %s : %s\n" , sdp->metafs_path, -strerror (errno)); +return -1 ; ret =mount (sdp->path_name, sdp->metafs_path,"gfs2meta" ,0 ,NULL );if (ret) {rmdir (sdp->metafs_path); -die ("Couldn't mount %s : %s\n" , sdp->metafs_path, -strerror (errno)); +return -1 ; } -lock_for_admin (sdp); +if (lock_for_admin (sdp)) +return -1 ; +return 0 ; }void cleanup_metafs (struct gfs2_sbd *sdp)
gfs2/mkfs/main_grow.c +5 -1
@@ -295,7 +295,11 @@ main_grow(int argc, char *argv[])die ("gfs: Error reading superblock.\n" );fix_device_geometry (sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }sprintf (rindex_name,"%s/rindex" , sdp->metafs_path); rindex_fd =open (rindex_name, (test ?O_RDONLY :O_RDWR ));
gfs2/mkfs/main_jadd.c +5 -1
@@ -507,7 +507,11 @@ main_jadd(int argc, char *argv[])gather_info (sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }compute_constants (sdp);find_current_journals (sdp);
gfs2/quota/check.c +10 -2
@@ -188,7 +188,11 @@ read_quota_file(struct gfs2_sbd *sdp, commandline_t *comline,exit (-1 ); }read_superblock (&sdp->sd_sb, sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }strcpy (quota_file, sdp->metafs_path);strcat (quota_file,"/quota" );
@@ -467,7 +471,11 @@ set_list(struct gfs2_sbd *sdp, commandline_t *comline, int user,exit (-1 ); }read_superblock (&sdp->sd_sb, sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }strcpy (quota_file, sdp->metafs_path);strcat (quota_file,"/quota" );
gfs2/quota/main.c +20 -4
@@ -515,7 +515,11 @@ do_reset(struct gfs2_sbd *sdp, commandline_t *comline)exit (-1 ); }read_superblock (&sdp->sd_sb, sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }strcpy (quota_file, sdp->metafs_path);strcat (quota_file,"/quota" );
@@ -579,7 +583,11 @@ do_list(struct gfs2_sbd *sdp, commandline_t *comline)exit (-1 ); }read_superblock (&sdp->sd_sb, sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }strcpy (quota_file, sdp->metafs_path);strcat (quota_file,"/quota" );
@@ -673,7 +681,11 @@ do_get_one(struct gfs2_sbd *sdp, commandline_t *comline, char *filesystem)exit (-1 ); }read_superblock (&sdp->sd_sb, sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }strcpy (quota_file, sdp->metafs_path);strcat (quota_file,"/quota" );
@@ -845,7 +857,11 @@ do_set(struct gfs2_sbd *sdp, commandline_t *comline)exit (-1 ); }read_superblock (&sdp->sd_sb, sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }strcpy (quota_file, sdp->metafs_path);strcat (quota_file,"/quota" );
gfs2/tool/df.c +5 -1
@@ -165,7 +165,11 @@ do_df_one(char *path) (get_sysfs_uint(fs, "args/localcaching")) ? "TRUE" : "FALSE");/* Read the master statfs file */ -mount_gfs2_meta (&sbd); +if (mount_gfs2_meta (&sbd)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }sprintf (statfs_fn,"%s/statfs" , sbd.metafs_path); statfs_fd =open (statfs_fn,O_RDONLY );
gfs2/tool/misc.c +6 -1
@@ -328,7 +328,12 @@ print_journals(int argc, char **argv)if (sbd.device_fd <0 )die ("can't open device %s: %s\n" , sbd.device_name,strerror (errno)); -mount_gfs2_meta (&sbd); + +if (mount_gfs2_meta (&sbd)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }sprintf (jindex_name,"%s/jindex" , sbd.metafs_path); jindex =opendir (jindex_name);
Signature · 1 line
1.6.2
PATCH 1/1 gfs2-utils: Remove 'die' calls from mount_gfs2_meta
Hi,
Looks good to me,
Steve.
Quoted 245 lines · Andrew Price
This patch removes the calls to 'die' from
mount_gfs2_metaand adds error reporting: It now returns -1 with errno set. All callers of this function are updated to check for errors.The static function
lock_for_admingets similar treatment asmount_gfs2_metais its only caller.Signed-off-by Andrew Price <[email protected]>--- gfs2/libgfs2/libgfs2.h | 2 +- gfs2/libgfs2/misc.c | 20 ++++++++++---------- gfs2/mkfs/main_grow.c | 6 +++++- gfs2/mkfs/main_jadd.c | 6 +++++- gfs2/quota/check.c | 12 ++++++++++-- gfs2/quota/main.c | 24 ++++++++++++++++++++---- gfs2/tool/df.c | 6 +++++- gfs2/tool/misc.c | 7 ++++++- 8 files changed, 62 insertions(+), 21 deletions(-)gfs2/libgfs2/libgfs2.h +1
-1@@ -628,7 +628,7 @@ extern void compute_constants(struct gfs2_sbd *sdp);extern int find_gfs2_meta (struct gfs2_sbd *sdp);extern int dir_exists (const char *dir);extern int check_for_gfs2 (struct gfs2_sbd *sdp); -extern void mount_gfs2_meta (struct gfs2_sbd *sdp); +extern int mount_gfs2_meta (struct gfs2_sbd *sdp);extern void cleanup_metafs (struct gfs2_sbd *sdp);extern char *find_debugfs_mount (void );extern char *mp2fsname (char *mp);gfs2/libgfs2/misc.c +10
-10@@ -148,7 +148,7 @@ int check_for_gfs2(struct gfs2_sbd *sdp)return -1 ; } -static void lock_for_admin (struct gfs2_sbd *sdp) +static int lock_for_admin (struct gfs2_sbd *sdp) {int error;@@ -157,18 +157,18 @@ static void lock_for_admin(struct gfs2_sbd *sdp) sdp->metafs_fd =open (sdp->metafs_path,O_RDONLY |O_NOFOLLOW );if (sdp->metafs_fd <0 ) -die ("can't open %s: %s\n" , - sdp->metafs_path,strerror (errno)); +return -1 ; error =flock (sdp->metafs_fd,LOCK_EX );if (error) -die ("can't flock %s: %s\n" , sdp->metafs_path,strerror (errno)); +return -1 ;if (sdp->debug)printf ("Got it.\n" ); +return 0 ; } -void mount_gfs2_meta (struct gfs2_sbd *sdp) +int mount_gfs2_meta (struct gfs2_sbd *sdp) {int ret;@@ -176,16 +176,16 @@ void mount_gfs2_meta(struct gfs2_sbd *sdp)snprintf (sdp->metafs_path,PATH_MAX -1 ,"/tmp/.gfs2meta.XXXXXX" );if (!mkdtemp (sdp->metafs_path)) -die ("Couldn't create %s : %s\n" , sdp->metafs_path, -strerror (errno)); +return -1 ; ret =mount (sdp->path_name, sdp->metafs_path,"gfs2meta" ,0 ,NULL );if (ret) {rmdir (sdp->metafs_path); -die ("Couldn't mount %s : %s\n" , sdp->metafs_path, -strerror (errno)); +return -1 ; } -lock_for_admin (sdp); +if (lock_for_admin (sdp)) +return -1 ; +return 0 ; }void cleanup_metafs (struct gfs2_sbd *sdp)gfs2/mkfs/main_grow.c +5
-1@@ -295,7 +295,11 @@ main_grow(int argc, char *argv[])die ("gfs: Error reading superblock.\n" );fix_device_geometry (sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }sprintf (rindex_name,"%s/rindex" , sdp->metafs_path); rindex_fd =open (rindex_name, (test ?O_RDONLY :O_RDWR ));gfs2/mkfs/main_jadd.c +5
-1@@ -507,7 +507,11 @@ main_jadd(int argc, char *argv[])gather_info (sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }compute_constants (sdp);find_current_journals (sdp);gfs2/quota/check.c +10
-2@@ -188,7 +188,11 @@ read_quota_file(struct gfs2_sbd *sdp, commandline_t *comline,exit (-1 ); }read_superblock (&sdp->sd_sb, sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }strcpy (quota_file, sdp->metafs_path);strcat (quota_file,"/quota" );@@ -467,7 +471,11 @@ set_list(struct gfs2_sbd *sdp, commandline_t *comline, int user,exit (-1 ); }read_superblock (&sdp->sd_sb, sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }strcpy (quota_file, sdp->metafs_path);strcat (quota_file,"/quota" );gfs2/quota/main.c +20
-4@@ -515,7 +515,11 @@ do_reset(struct gfs2_sbd *sdp, commandline_t *comline)exit (-1 ); }read_superblock (&sdp->sd_sb, sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }strcpy (quota_file, sdp->metafs_path);strcat (quota_file,"/quota" );@@ -579,7 +583,11 @@ do_list(struct gfs2_sbd *sdp, commandline_t *comline)exit (-1 ); }read_superblock (&sdp->sd_sb, sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }strcpy (quota_file, sdp->metafs_path);strcat (quota_file,"/quota" );@@ -673,7 +681,11 @@ do_get_one(struct gfs2_sbd *sdp, commandline_t *comline, char *filesystem)exit (-1 ); }read_superblock (&sdp->sd_sb, sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }strcpy (quota_file, sdp->metafs_path);strcat (quota_file,"/quota" );@@ -845,7 +857,11 @@ do_set(struct gfs2_sbd *sdp, commandline_t *comline)exit (-1 ); }read_superblock (&sdp->sd_sb, sdp); -mount_gfs2_meta (sdp); +if (mount_gfs2_meta (sdp)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }strcpy (quota_file, sdp->metafs_path);strcat (quota_file,"/quota" );gfs2/tool/df.c +5
-1@@ -165,7 +165,11 @@ do_df_one(char *path) (get_sysfs_uint(fs, "args/localcaching")) ? "TRUE" : "FALSE");/* Read the master statfs file */ -mount_gfs2_meta (&sbd); +if (mount_gfs2_meta (&sbd)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }sprintf (statfs_fn,"%s/statfs" , sbd.metafs_path); statfs_fd =open (statfs_fn,O_RDONLY );gfs2/tool/misc.c +6
-1@@ -328,7 +328,12 @@ print_journals(int argc, char **argv)if (sbd.device_fd <0 )die ("can't open device %s: %s\n" , sbd.device_name,strerror (errno)); -mount_gfs2_meta (&sbd); + +if (mount_gfs2_meta (&sbd)) { +fprintf (stderr,"Error mounting GFS2 metafs: %s\n" , +strerror (errno)); +exit (-1 ); + }sprintf (jindex_name,"%s/jindex" , sbd.metafs_path); jindex =opendir (jindex_name);