libgfs2 cleanups
Hi,
This patch set is working towards removing all the user interface code from libgfs2. There will be more patches to follow. Once all of the log_xxx() functions are moved out from libgfs2 then we can move the macros into the individual utilities which should more or less complete the job,
Steve.
PATCH 1/6 libgfs2: Move generic_interrupt() into utils
First patch moving user interface code out of the library
--- gfs2/convert/gfs2_convert.c | 48 +++++++++++++++++++++++++++++++++++++++++++ gfs2/fsck/util.c | 48 +++++++++++++++++++++++++++++++++++++++++++ gfs2/fsck/util.h | 4 +++ gfs2/libgfs2/gfs2_log.c | 48 ------------------------------------------- gfs2/libgfs2/libgfs2.h | 3 -- 5 files changed, 100 insertions(+), 51 deletions(-)
gfs2/convert/gfs2_convert.c +48 -0
@@ -2057,6 +2057,54 @@ static void copy_quotas(struct gfs2_sbd *sdp)inode_put (&oq_ip); } + +static char generic_interrupt (const char *caller,const char *where, +const char *progress,const char *question, +const char *answers) +{ +fd_set rfds; +struct timeval tv; +char response; +int err, i; + +FD_ZERO (&rfds); +FD_SET (STDIN_FILENO , &rfds); + + tv.tv_sec =0 ; + tv.tv_usec =0 ; +/* Make sure there isn't extraneous input before asking the +* user the question */ +while ((err =select (STDIN_FILENO +1 , &rfds,NULL ,NULL , &tv))) { +if (err <0 ) { +log_debug ("Error in select() on stdin\n" ); +break ; + } +if (read (STDIN_FILENO , &response,sizeof (char )) <0 ) { +log_debug ("Error in read() on stdin\n" ); +break ; + } + } +while (TRUE) { +printf ("\n%s interrupted during %s: " , caller, where); +if (progress) +printf ("%s.\n" , progress); +printf ("%s" , question); + +/* Make sure query is printed out */ +fflush (NULL ); + response =gfs2_getch (); +printf ("\n" ); +fflush (NULL ); +if (strchr (answers, response)) +break ; +printf ("Bad response, please type " ); +for (i =0 ; i <strlen (answers) -1 ; i++) +printf ("'%c', " , answers[i]); +printf (" or '%c'.\n" , answers[i]); + } +return response; +} +static int __attribute__((format (printf,3 ,4 )))gfs2_query (int *setonabort,struct gfs2_options *opts,const char *format, ...) {
gfs2/fsck/util.c +48 -0
54 lines not on this page · raw message
gfs2/fsck/util.h +4 -0
@@ -180,4 +180,8 @@ extern void *gfs2_bmap_destroy(struct gfs2_sbd *sdp, struct gfs2_bmap *il);extern int gfs2_blockmap_set (struct gfs2_bmap *il,uint64_t block,enum gfs2_mark_block mark);extern int set_ip_blockmap (struct gfs2_inode *ip,int instree); +extern char generic_interrupt (const char *caller,const char *where, +const char *progress,const char *question, +const char *answers); +#endif /* __UTIL_H__ */
gfs2/libgfs2/gfs2_log.c +0 -48
51 lines not on this page · raw message
gfs2/libgfs2/libgfs2.h +0 -3
@@ -662,9 +662,6 @@ extern void decrease_verbosity(void);extern void print_fsck_log (int priority,const char *file,int line,const char *format, ...) __attribute__((format (printf,4 ,5 ))); -extern char generic_interrupt (const char *caller,const char *where, -const char *progress,const char *question, -const char *answers);/* misc.c */ extern int compute_heightsize(struct gfs2_sbd *sdp, uint64_t *heightsize,
Signature · 1 line
1.7.4.4
PATCH 2/6 libgfs2: Move gfs2_getch into utils
In reply to Steven WhitehouseMore UI code being moved out of the library.
--- gfs2/convert/gfs2_convert.c | 36 ++++++++++++++++++++++++++++++++---- gfs2/fsck/util.c | 28 ++++++++++++++++++++++++++++ gfs2/fsck/util.h | 1 + gfs2/libgfs2/gfs2_log.c | 28 ---------------------------- gfs2/libgfs2/libgfs2.h | 1 - 5 files changed, 61 insertions(+), 33 deletions(-)
gfs2/convert/gfs2_convert.c +32 -4
@@ -23,6 +23,7 @@#include <sys/time.h> #include <errno.h> #include <ctype.h> +#include <termios.h> #include <libintl.h> #include <locale.h> #define _ (String) gettext(String)
@@ -2057,24 +2058,51 @@ static void copy_quotas(struct gfs2_sbd *sdp)inode_put (&oq_ip); } +static char gfs2_getch (void ) +{ +struct termios termattr, savetermattr; +char ch; +ssize_t size; + +tcgetattr (STDIN_FILENO , &termattr); + savetermattr = termattr; + termattr.c_lflag &= ~(ICANON |IEXTEN |ISIG ); + termattr.c_iflag &= ~(BRKINT |ICRNL |INPCK |ISTRIP |IXON ); + termattr.c_cflag &= ~(CSIZE |PARENB ); + termattr.c_cflag |=CS8 ; + termattr.c_oflag &= ~(OPOST ); + termattr.c_cc[VMIN ] =0 ; + termattr.c_cc[VTIME ] =0 ; + +tcsetattr (STDIN_FILENO ,TCSANOW , &termattr); +do { + size =read (STDIN_FILENO , &ch,1 ); +if (size) +break ; +usleep (50000 ); + }while (!size); + +tcsetattr (STDIN_FILENO ,TCSANOW , &savetermattr); +return ch; +}static char generic_interrupt (const char *caller,const char *where,const char *progress,const char *question,const char *answers) {fd_set rfds; -struct timeval tv; +struct timeval stv;char response;int err, i;FD_ZERO (&rfds);FD_SET (STDIN_FILENO , &rfds); - tv.tv_sec =0 ; - tv.tv_usec =0 ; + stv.tv_sec =0 ; + stv.tv_usec =0 ;/* Make sure there isn't extraneous input before asking the * user the question */ -while ((err =select (STDIN_FILENO +1 , &rfds,NULL ,NULL , &tv))) { +while ((err =select (STDIN_FILENO +1 , &rfds,NULL ,NULL , &stv))) {if (err <0 ) {log_debug ("Error in select() on stdin\n" );break ;
gfs2/fsck/util.c +28 -0
@@ -6,6 +6,7 @@#include <unistd.h> #include <sys/time.h> #include <stdio.h> +#include <termios.h> #include <libintl.h> #include <ctype.h> #define _ (String) gettext(String)
@@ -87,6 +88,33 @@ void warm_fuzzy_stuff(uint64_t block) } } +char gfs2_getch (void ) +{ +struct termios termattr, savetermattr; +char ch; +ssize_t size; + +tcgetattr (STDIN_FILENO , &termattr); + savetermattr = termattr; + termattr.c_lflag &= ~(ICANON |IEXTEN |ISIG ); + termattr.c_iflag &= ~(BRKINT |ICRNL |INPCK |ISTRIP |IXON ); + termattr.c_cflag &= ~(CSIZE |PARENB ); + termattr.c_cflag |=CS8 ; + termattr.c_oflag &= ~(OPOST ); + termattr.c_cc[VMIN ] =0 ; + termattr.c_cc[VTIME ] =0 ; + +tcsetattr (STDIN_FILENO ,TCSANOW , &termattr); +do { + size =read (STDIN_FILENO , &ch,1 ); +if (size) +break ; +usleep (50000 ); + }while (!size); + +tcsetattr (STDIN_FILENO ,TCSANOW , &savetermattr); +return ch; +} char generic_interrupt(const char *caller, const char *where, const char *progress, const char *question,
gfs2/fsck/util.h +1 -0
@@ -183,5 +183,6 @@ extern int set_ip_blockmap(struct gfs2_inode *ip, int instree);extern char generic_interrupt (const char *caller,const char *where,const char *progress,const char *question,const char *answers); +extern char gfs2_getch (void );#endif /* __UTIL_H__ */
gfs2/libgfs2/gfs2_log.c +0 -28
@@ -56,31 +56,3 @@ void print_fsck_log(int priority, const char *file, int line,print_msg (priority, file, line, format, args);va_end (args); } - -char gfs2_getch (void ) -{ -struct termios termattr, savetermattr; -char ch; -ssize_t size; - -tcgetattr (STDIN_FILENO , &termattr); - savetermattr = termattr; - termattr.c_lflag &= ~(ICANON |IEXTEN |ISIG ); - termattr.c_iflag &= ~(BRKINT |ICRNL |INPCK |ISTRIP |IXON ); - termattr.c_cflag &= ~(CSIZE |PARENB ); - termattr.c_cflag |=CS8 ; - termattr.c_oflag &= ~(OPOST ); - termattr.c_cc[VMIN ] =0 ; - termattr.c_cc[VTIME ] =0 ; - -tcsetattr (STDIN_FILENO ,TCSANOW , &termattr); -do { - size =read (STDIN_FILENO , &ch,1 ); -if (size) -break ; -usleep (50000 ); - }while (!size); - -tcsetattr (STDIN_FILENO ,TCSANOW , &savetermattr); -return ch; -}
gfs2/libgfs2/libgfs2.h +0 -1
@@ -656,7 +656,6 @@ extern int print_level;#define stack log_debug("<backtrace> - %s()\n", __func__) -extern char gfs2_getch (void );extern void increase_verbosity (void );extern void decrease_verbosity (void ); extern void print_fsck_log(int priority, const char *file, int line,
Signature · 1 line
1.7.4.4
PATCH 3/6 libgfs2: Prepare to remove log_xxx() macros from library
In reply to Steven WhitehouseThis will need to be done in stages. The first stage is to clean up what is there. There are calls to the log_ functions in the library itself, and those will need to be removed in later patches.
This patch moves the gfs2_options structure into the two utils which actually require it, removes the print_fsck_log function, replacing the 3 calls to it from fsck with the equivalent printf functions - it looks like those could be merged in future as they all look very similar.
The log_ macros are also updated, so that they will do excatly the same as before, but now don't depend on any code in libgfs2 itself.
--- gfs2/convert/gfs2_convert.c | 7 +++++++ gfs2/fsck/fsck.h | 7 +++++++ gfs2/fsck/metawalk.c | 40 ++++++++++++++++++---------------------- gfs2/fsck/util.h | 1 + gfs2/libgfs2/gfs2_log.c | 34 ---------------------------------- gfs2/libgfs2/libgfs2.h | 29 +++++++++-------------------- gfs2/libgfs2/super.c | 2 +- 7 files changed, 43 insertions(+), 77 deletions(-)
gfs2/convert/gfs2_convert.c +7 -0
@@ -139,6 +139,13 @@ struct blocklist {char *ptrbuf; }; +struct gfs2_options { +char *device; +unsigned int yes:1 ; +unsigned int no:1 ; +unsigned int query:1 ; +}; +struct gfs1_sb raw_gfs1_ondisk_sb;struct gfs2_sbd sb2;char device[256 ];
gfs2/fsck/fsck.h +7 -0
@@ -124,6 +124,13 @@ extern void dirtree_delete(struct dir_info *b);* of pass1 and put somewhere else... */ struct dir_info *dirtree_insert (uint64_t dblock); +struct gfs2_options { +char *device; +unsigned int yes:1 ; +unsigned int no:1 ; +unsigned int query:1 ; +}; +extern struct gfs2_options opts;extern struct gfs2_inode *lf_dip;/* Lost and found directory inode */ extern struct gfs2_bmap *bl;
gfs2/fsck/metawalk.c +18 -22
@@ -129,38 +129,34 @@ int _fsck_blockmap_set(struct gfs2_inode *ip, uint64_t bblock,log_info ("\n" ); prevcount =0 ; } -print_fsck_log (MSG_DEBUG , caller, fline, -_ ("%s inode found at block " -"(0x%llx): marking as '%s'\n" ), - btype, (unsigned long long ) - ip->i_di.di_num.no_addr, -block_type_string (mark)); +printf (_ ("(%s:%d) %s inode found at block " +"(0x%llx): marking as '%s'\n" ), caller, fline, + btype, + (unsigned long long )ip->i_di.di_num.no_addr, +block_type_string (mark)); + }else if (mark == gfs2_bad_block || mark == gfs2_meta_inval) {if (prevcount) {log_info ("\n" ); prevcount =0 ; } -print_fsck_log (MSG_DEBUG , caller, fline, -_ ("inode (0x%llx) references " -"%s block (0x%llx): " -"marking as '%s'\n" ), - (unsigned long long ) - ip->i_di.di_num.no_addr, - btype, (unsigned long long )bblock, -block_type_string (mark)); +printf (_ ("(%s:%d) inode (0x%llx) references %s block" +" (0x%llx): marking as '%s'\n" ), + caller, fline, + (unsigned long long )ip->i_di.di_num.no_addr, + btype, (unsigned long long )bblock, +block_type_string (mark)); }else {if (prevcount) {log_info ("\n" ); prevcount =0 ; } -print_fsck_log (MSG_DEBUG , caller, fline, -_ ("inode (0x%llx) references " -"%s block (0x%llx): " -"marking as '%s'\n" ), - (unsigned long long ) - ip->i_di.di_num.no_addr, btype, - (unsigned long long )bblock, -block_type_string (mark)); +printf (_ ("(%s:%d) inode (0x%llx) references %s block" +" (0x%llx): marking as '%s'\n" ), + caller, fline, + (unsigned long long )ip->i_di.di_num.no_addr, + btype, (unsigned long long )bblock, +block_type_string (mark)); } prev_ino_addr = ip->i_di.di_num.no_addr; prev_mark = mark;
gfs2/fsck/util.h +1 -0
@@ -184,5 +184,6 @@ extern char generic_interrupt(const char *caller, const char *where, const char *progress, const char *question, const char *answers);extern char gfs2_getch (void ); +#define stack log_debug("<backtrace> - %s()\n", __func__)#endif /* __UTIL_H__ */
gfs2/libgfs2/gfs2_log.c +0 -34
@@ -22,37 +22,3 @@ void decrease_verbosity(void) { print_level--; } - -static __attribute__((format (printf,4 ,0 ))) -void print_msg (int priority,const char *file,int line, -const char *format,va_list args) { - -switch (priority) { - -case MSG_DEBUG : -printf ("(%s:%d) " , file, line); -vprintf (format, args); -break ; -case MSG_INFO : -case MSG_NOTICE : -case MSG_WARN : -vprintf (format, args); -fflush (NULL ); -break ; -case MSG_ERROR : -case MSG_CRITICAL : -default : -vfprintf (stderr, format, args); -break ; - } -} - - -void print_fsck_log (int priority,const char *file,int line, -const char *format, ...) -{ -va_list args; -va_start (args, format); -print_msg (priority, file, line, format, args); -va_end (args); -}
gfs2/libgfs2/libgfs2.h +9 -20
@@ -617,12 +617,6 @@ extern void gfs_put_leaf_nr(struct gfs2_inode *dip, uint32_t inx, uint64_t leaf_out);/* gfs2_log.c */ -struct gfs2_options { -char *device; -unsigned int yes:1 ; -unsigned int no:1 ; -unsigned int query:1 ; -};extern int print_level;
@@ -634,33 +628,28 @@ extern int print_level;#define MSG_CRITICAL 2#define MSG_NULL 1 -#define print_log(priority, format...) \ - do { print_fsck_log(priority, __FUNCTION__, __LINE__, ## format); } while(0) - #define log_debug(format...) \ - do { if(print_level >= MSG_DEBUG) print_log(MSG_DEBUG, format); } while(0) + do { if (print_level >= MSG_DEBUG) { \ + printf("(%s:%d) ", __FUNCTION__, __LINE__); \ + printf(format); } } while(0) + #define log_info(format...) \ - do { if(print_level >= MSG_INFO) print_log(MSG_INFO, format); } while(0) + do { if (print_level >= MSG_INFO) printf(format); } while(0) #define log_notice(format...) \ - do { if(print_level >= MSG_NOTICE) print_log(MSG_NOTICE, format); } while(0) + do { if (print_level >= MSG_NOTICE) printf(format); } while(0) #define log_warn(format...) \ - do { if(print_level >= MSG_WARN) print_log(MSG_WARN, format); } while(0) + do { if (print_level >= MSG_WARN) printf(format); } while(0) #define log_err(format...) \ - do { if(print_level >= MSG_ERROR) print_log(MSG_ERROR, format); } while(0) + do { if (print_level >= MSG_ERROR) fprintf(stderr, format); } while(0) #define log_crit(format...) \ - do { if(print_level >= MSG_CRITICAL) print_log(MSG_CRITICAL, format); } while(0) - -#define stack log_debug("<backtrace> - %s()\n", __func__) + do { if (print_level >= MSG_CRITICAL) fprintf(stderr, format); } while(0)extern void increase_verbosity (void );extern void decrease_verbosity (void ); -extern void print_fsck_log (int priority,const char *file,int line, -const char *format, ...) - __attribute__((format (printf,4 ,5 )));/* misc.c */ extern int compute_heightsize(struct gfs2_sbd *sdp, uint64_t *heightsize,
gfs2/libgfs2/super.c +1 -1
@@ -28,7 +28,7 @@ int check_sb(struct gfs2_sb *sb, int allow_gfs) sb->sb_header.mh_type != GFS2_METATYPE_SB) {log_crit ("Either the super block is corrupted, or this " "is not a GFS2 filesystem\n" ); -log_debug ("Header magic: %X Header Type: %X\n" , +log_crit ("Header magic: %X Header Type: %X\n" , sb->sb_header.mh_magic, sb->sb_header.mh_type);return -EINVAL ;
Signature · 1 line
1.7.4.4
PATCH 4/6 libgfs2: Move some debug messages out into mkfs/fsck
In reply to Steven WhitehouseWe don't need to print these messages from the function which calculates the resource group layout, we can do it afterwards. There are still some other messages which need to be relocated from this function, but that is a more tricky operation.
--- gfs2/fsck/rgrepair.c | 19 +++++++++++++++++++ gfs2/libgfs2/fs_geometry.c | 12 ------------ gfs2/mkfs/gfs2_mkfs.h | 9 +++++---- gfs2/mkfs/main_grow.c | 19 +++++++++++++++++++ gfs2/mkfs/main_mkfs.c | 1 + 5 files changed, 44 insertions(+), 16 deletions(-)
gfs2/fsck/rgrepair.c +19 -0
@@ -593,6 +593,24 @@ static int gfs2_rindex_rebuild(struct gfs2_sbd *sdp, int *num_rgs,return 0 ; } +static void debug_print_rgrps (struct gfs2_sbd *sdp,struct osi_root *rgtree) +{ +struct osi_node *n, *next; +struct rgrp_tree *rl; + +if (sdp->debug) { +log_info ("\n" ); + +for (n =osi_first (rgtree); n; n = next) { + next =osi_next (n); + rl = (struct rgrp_tree *)n; +log_info ("rg_o = %llu, rg_l = %llu\n" , + (unsigned long long )rl->start, + (unsigned long long )rl->length); + } + } +} +/* * gfs2_rindex_calculate - calculate what the rindex should look like * in a perfect world (trust_lvl == open_minded)
@@ -643,6 +661,7 @@ static int gfs2_rindex_calculate(struct gfs2_sbd *sdp, int *num_rgs) }/* Compute the default resource group layout as mkfs would have done */ compute_rgrp_layout (sdp, &sdp->rgcalc, TRUE); +debug_print_rgrps (sdp, &sdp->rgcalc);build_rgrps (sdp, FALSE);/* FALSE = calc but don't write to disk. */ log_debug (_ ("fs_total_size = 0x%llx blocks.\n" ), (unsigned long long )sdp->device.length);
gfs2/libgfs2/fs_geometry.c +0 -12
@@ -142,18 +142,6 @@ void compute_rgrp_layout(struct gfs2_sbd *sdp, struct osi_root *rgtree, } sdp->rgrps = nrgrp; - -if (sdp->debug) { -log_info ("\n" ); - -for (n =osi_first (rgtree); n; n = next) { - next =osi_next (n); - rl = (struct rgrp_tree *)n; -log_info ("rg_o = %llu, rg_l = %llu\n" , - (unsigned long long )rl->start, - (unsigned long long )rl->length); - } - } }/**
gfs2/mkfs/gfs2_mkfs.h +5 -4
@@ -6,16 +6,17 @@#include "copyright.cf" /* main_grow */ -void main_grow (int argc,char *argv[]); +extern void main_grow (int argc,char *argv[]); +extern void debug_print_rgrps (struct gfs2_sbd *sdp,struct osi_root *rgtree);/* main_jadd */ -void main_jadd (int argc,char *argv[]); +extern void main_jadd (int argc,char *argv[]);/* main_mkfs */ -void main_mkfs (int argc,char *argv[]); +extern void main_mkfs (int argc,char *argv[]);/* main_shrink */ -void main_shrink (int argc,char *argv[]); +extern void main_shrink (int argc,char *argv[]);/* * The following inode IOCTL macros and inode flags
gfs2/mkfs/main_grow.c +19 -0
@@ -284,6 +284,24 @@ static void print_info(struct gfs2_sbd *sdp) (unsigned long long)fsgrowth / MB); } +void debug_print_rgrps (struct gfs2_sbd *sdp,struct osi_root *rgtree) +{ +struct osi_node *n, *next; +struct rgrp_tree *rl; + +if (sdp->debug) { +log_info ("\n" ); + +for (n =osi_first (rgtree); n; n = next) { + next =osi_next (n); + rl = (struct rgrp_tree *)n; +log_info ("rg_o = %llu, rg_l = %llu\n" , + (unsigned long long )rl->start, + (unsigned long long )rl->length); + } + } +} +/** * main_grow - do everything * @argc:
@@ -391,6 +409,7 @@ main_grow(int argc, char *argv[])int old_rg_count;compute_rgrp_layout (sdp, &sdp->rgtree, TRUE); +debug_print_rgrps (sdp, &sdp->rgtree);print_info (sdp);initialize_new_portion (sdp, &old_rg_count);fix_rindex (sdp, rindex_fd, old_rg_count);
gfs2/mkfs/main_mkfs.c +1 -0
@@ -629,6 +629,7 @@ void main_mkfs(int argc, char *argv[])/* Compute the resource group layouts */ compute_rgrp_layout (sdp, &sdp->rgtree, rgsize_specified); +debug_print_rgrps (sdp, &sdp->rgtree);/* Generate a random uuid */ get_random_bytes (uuid,sizeof (uuid));
Signature · 1 line
1.7.4.4
PATCH 5/6 libgfs2: Clean up sb read/check functions
In reply to Steven WhitehouseThere is no need to specify in advance whether we want to accept gfs1 format super blocks or not. We can simply return that info and let the caller decide if gfs1 format is acceptable or not.
We can also remove the message regarding the magic number of the superblock, since the caller prints out a message anyway if the check fails.
That removes some more of the log_ messages from libgfs2 as a result.
--- gfs2/edit/savemeta.c | 4 ++-- gfs2/fsck/initialize.c | 4 ++-- gfs2/libgfs2/libgfs2.h | 4 ++-- gfs2/libgfs2/super.c | 23 ++++++----------------- gfs2/mkfs/main_grow.c | 6 ++++-- 5 files changed, 16 insertions(+), 25 deletions(-)
gfs2/edit/savemeta.c +2 -2
@@ -670,7 +670,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)fprintf (stderr,"Bad constants (1)\n" );exit (-1 ); } - ret =read_sb (&sbd,1 ); + ret =read_sb (&sbd);if (ret <0 ) { slow = TRUE; sbd.gfs1 =0 ;
@@ -911,7 +911,7 @@ static int restore_data(int fd, gzFile *gzin_fd, int printblocksonly,memcpy (&bufsb, savedata->buf,sizeof (bufsb));gfs2_sb_in (&sbd.sd_sb, &dummy_bh); sbd1 = (struct gfs_sb *)&sbd.sd_sb; - ret =check_sb (&sbd.sd_sb,1 ); + ret =check_sb (&sbd.sd_sb);if (ret <0 ) {fprintf (stderr,"Error: Invalid superblock data.\n" );return -1 ;
gfs2/fsck/initialize.c +2 -2
@@ -1227,12 +1227,12 @@ static int fill_super_block(struct gfs2_sbd *sdp)log_crit (_ ("Bad constants (1)\n" ));exit (FSCK_ERROR ); } - ret =read_sb (sdp,1 ); + ret =read_sb (sdp);if (ret <0 ) {if (sb_repair (sdp) !=0 )return -1 ;/* unrepairable, so exit */ /* Now that we've tried to repair it, re-read it. */ - ret =read_sb (sdp,1 ); + ret =read_sb (sdp);if (ret <0 )return -1 ; }
gfs2/libgfs2/libgfs2.h +2 -2
@@ -722,8 +722,8 @@ extern int gfs2_next_rg_freemeta(struct rgrp_tree *rgd, uint64_t *block, int first);/* super.c */ -extern int check_sb (struct gfs2_sb *sb,int allow_gfs); -extern int read_sb (struct gfs2_sbd *sdp,int allow_gfs); +extern int check_sb (struct gfs2_sb *sb); +extern int read_sb (struct gfs2_sbd *sdp);extern int rindex_read (struct gfs2_sbd *sdp,int fd,int *count1,int *sane);extern int ri_update (struct gfs2_sbd *sdp,int fd,int *rgcount,int *sane);extern int write_sb (struct gfs2_sbd *sdp);
gfs2/libgfs2/super.c +6 -17
@@ -13,7 +13,6 @@/** * check_sb - Check superblock -* @sdp: the filesystem * @sb: The superblock * * Checks the version code of the FS is one that we understand how to
@@ -22,25 +21,17 @@* * Returns: -1 on failure, 1 if this is gfs (gfs1), 2 if this is gfs2 */ -int check_sb (struct gfs2_sb *sb,int allow_gfs) +int check_sb (struct gfs2_sb *sb) {if (sb->sb_header.mh_magic !=GFS2_MAGIC || sb->sb_header.mh_type !=GFS2_METATYPE_SB ) { -log_crit ("Either the super block is corrupted, or this " -"is not a GFS2 filesystem\n" ); -log_crit ("Header magic: %X Header Type: %X\n" , - sb->sb_header.mh_magic, - sb->sb_header.mh_type); -return -EINVAL ; + errno = -EIO ; +return -1 ; }if (sb->sb_fs_format ==GFS_FORMAT_FS && sb->sb_header.mh_format ==GFS_FORMAT_SB && sb->sb_multihost_format ==GFS_FORMAT_MULTI ) { -if (allow_gfs) -return 1 ; - -log_crit ("Old gfs1 file system detected.\n" ); -return -EINVAL ; +return 1 ; }return 2 ; }
@@ -54,12 +45,10 @@ int check_sb(struct gfs2_sb *sb, int allow_gfs)* initializes various constants maintained in the super * block * -* allow_gfs - passed in as 1 if we're allowed to accept gfs1 file systems -* * Returns: 0 on success, -1 on failure * sdp->gfs1 will be set if this is gfs (gfs1) */ -int read_sb (struct gfs2_sbd *sdp,int allow_gfs) +int read_sb (struct gfs2_sbd *sdp) {struct gfs2_buffer_head *bh;uint64_t space =0 ;
@@ -70,7 +59,7 @@ int read_sb(struct gfs2_sbd *sdp, int allow_gfs)gfs2_sb_in (&sdp->sd_sb, bh);brelse (bh); - ret =check_sb (&sdp->sd_sb, allow_gfs); + ret =check_sb (&sdp->sd_sb);if (ret <0 )return ret;if (ret ==1 )
gfs2/mkfs/main_grow.c +4 -2
@@ -358,9 +358,11 @@ main_grow(int argc, char *argv[])perror (_ ("Bad constants (1)" ));exit (EXIT_FAILURE ); } -if (read_sb (sdp,0 ) <0 ) +if (read_sb (sdp) <0 )die (_ ("gfs: Error reading superblock.\n" )); - +if (sdp->gfs1) { +die (_ ("cannot grow gfs1 filesystem\n" )); + }if (fix_device_geometry (sdp)) {fprintf (stderr,_ ("Device is too small (%llu bytes)\n" ), (unsigned long long )sdp->device.length <<GFS2_BASIC_BLOCK_SHIFT );
Signature · 1 line
1.7.4.4
PATCH 6/6 libgfs2: Remove some more log_xxx calls
In reply to Steven WhitehouseOne is changed to fprintf, on a temporary basis - really it should be removed. The others are removed and an error code returned.
--- gfs2/libgfs2/structures.c | 2 +- gfs2/libgfs2/super.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
gfs2/libgfs2/structures.c +1 -1
@@ -511,7 +511,7 @@ static int __gfs2_next_rg_meta(struct rgrp_tree *rgd, uint64_t *block,int i;if (!first && (*block < rgd->ri.ri_data0)) { -log_err ("next_rg_meta: Start block is outside rgrp bounds.\n" ); +fprintf (stderr,"next_rg_meta: Start block is outside rgrp bounds.\n" );exit (1 ); }for (i =0 ; i < length; i++){
gfs2/libgfs2/super.c +2 -2
@@ -96,7 +96,7 @@ int read_sb(struct gfs2_sbd *sdp) sdp->sd_heightsize[x] = space; }if (x >GFS2_MAX_META_HEIGHT ){ -log_err ("Bad max metadata height.\n" ); + errno =E2BIG ;return -1 ; }
@@ -111,7 +111,7 @@ int read_sb(struct gfs2_sbd *sdp) } sdp->sd_max_jheight = x;if (sdp->sd_max_jheight >GFS2_MAX_META_HEIGHT ) { -log_err ("Bad max jheight.\n" ); + errno =E2BIG ;return -1 ; } sdp->fssize =lseek (sdp->device_fd,0 ,SEEK_END ) / sdp->sd_sb.sb_bsize;
Signature · 1 line
1.7.4.4
----- Original Message -----
| Hi, | | This patch set is working towards removing all the user interface | code | from libgfs2. There will be more patches to follow. Once all of the | log_xxx() functions are moved out from libgfs2 then we can move the | macros into the individual utilities which should more or less | complete the job, | | Steve.
Hi,
ACK on all six patches.
Regards,
Bob Peterson
Red Hat File Systems