Whamcloud - gitweb
libsupport: fix gcc -Wall nits
authorTheodore Ts'o <tytso@mit.edu>
Sun, 29 May 2016 21:36:43 +0000 (17:36 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 29 May 2016 21:36:43 +0000 (17:36 -0400)
Also add better error checking to mke2fs and e2fsck's calls to quota
functions in libsupport.a.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
13 files changed:
e2fsck/problem.c
e2fsck/problem.h
e2fsck/unix.c
lib/support/common.h
lib/support/mkquota.c
lib/support/plausible.c
lib/support/profile.c
lib/support/profile.h
lib/support/profile_helpers.c
lib/support/quotaio.c
lib/support/quotaio_tree.c
misc/mke2fs.c
misc/tune2fs.c

index 1e645e4..ff91abd 100644 (file)
@@ -472,6 +472,11 @@ static struct e2fsck_problem problem_table[] = {
          N_("@S metadata_csum_seed is not necessary without metadata_csum."),
          PROMPT_FIX, PR_PREEN_OK | PR_NO_OK},
 
+       /* Error initializing quota context */
+       { PR_0_QUOTA_INIT_CTX,
+         N_("Error initializing quota context in support library: %m\n"),
+         PROMPT_NULL, PR_FATAL },
+
        /* Pass 1 errors */
 
        /* Pass 1: Checking inodes, blocks, and sizes */
@@ -2006,6 +2011,11 @@ static struct e2fsck_problem problem_table[] = {
          N_("Error flushing writes to storage device: %m\n"),
          PROMPT_NULL, PR_FATAL },
 
+       /* Error writing quota information */
+       { PR_6_WRITE_QUOTAS,
+         N_("Error writing quota info for quota type %N: %m\n"),
+         PROMPT_NULL, 0 },
+
        { 0 }
 };
 
index edc381d..fad05c5 100644 (file)
@@ -271,6 +271,10 @@ struct problem_context {
 /* metadata_csum_seed means nothing without metadata_csum */
 #define PR_0_CSUM_SEED_WITHOUT_META_CSUM       0x00004B
 
+/* Error initializing quota context */
+#define PR_0_QUOTA_INIT_CTX                    0x00004C
+
+
 /*
  * Pass 1 errors
  */
@@ -1212,6 +1216,10 @@ struct problem_context {
 /* Error flushing writes to storage device */
 #define PR_6_IO_FLUSH                  0x060005
 
+/* Error updating quota information */
+#define PR_6_WRITE_QUOTAS              0x060006
+
+
 /*
  * Function declarations
  */
index f9409f7..e00fa16 100644 (file)
@@ -1791,7 +1791,13 @@ print_unsupp_features:
                                qtype_bits |= 1 << qtype;
                }
 
-               quota_init_context(&ctx->qctx, ctx->fs, qtype_bits);
+               clear_problem_context(&pctx);
+               pctx.errcode = quota_init_context(&ctx->qctx, ctx->fs,
+                                                 qtype_bits);
+               if (pctx.errcode) {
+                       fix_problem(ctx, PR_0_QUOTA_INIT_CTX, &pctx);
+                       fatal_error(ctx, 0);
+               }
        }
 
        run_result = e2fsck_run(ctx);
@@ -1843,8 +1849,13 @@ no_journal:
                        retval = quota_compare_and_update(ctx->qctx, qtype,
                                                          &needs_writeout);
                        if ((retval || needs_writeout) &&
-                           fix_problem(ctx, PR_6_UPDATE_QUOTAS, &pctx))
-                               quota_write_inode(ctx->qctx, 1 << qtype);
+                           fix_problem(ctx, PR_6_UPDATE_QUOTAS, &pctx)) {
+                               pctx.errcode = quota_write_inode(ctx->qctx,
+                                                                1 << qtype);
+                               if (pctx.errcode)
+                                       (void) fix_problem(ctx,
+                                               PR_6_WRITE_QUOTAS, &pctx);
+                       }
                }
                quota_release_context(&ctx->qctx);
        }
index f1ad79f..19a75f4 100644 (file)
@@ -30,7 +30,7 @@
        fprintf(stderr, "[DEBUG] %s:%d:%s:: " format "\n",              \
                __FILE__, __LINE__, __func__, ## arg)
 #else
-# define log_debug(format, ...)
+# define log_debug(...)
 #endif
 
 #endif /* __QUOTA_COMMON_H__ */
index add60ca..fc3f556 100644 (file)
@@ -108,16 +108,19 @@ errcode_t quota_remove_inode(ext2_filsys fs, enum quota_type qtype)
 
        retval = ext2fs_read_bitmaps(fs);
        if (retval) {
-               log_err("Couldn't read bitmaps: %s", error_message(retval));
+               log_debug("Couldn't read bitmaps: %s", error_message(retval));
                return retval;
        }
+
        qf_ino = *quota_sb_inump(fs->super, qtype);
-       if (qf_ino < EXT2_FIRST_INODE(fs->super)) {
-               quota_inode_truncate(fs, qf_ino);
-       } else {
+       if (qf_ino == 0)
+               return 0;
+       retval = quota_inode_truncate(fs, qf_ino);
+       if (retval)
+               return retval;
+       if (qf_ino >= EXT2_FIRST_INODE(fs->super)) {
                struct ext2_inode inode;
 
-               quota_inode_truncate(fs, qf_ino);
                retval = ext2fs_read_inode(fs, qf_ino, &inode);
                if (!retval) {
                        memset(&inode, 0, sizeof(struct ext2_inode));
@@ -133,7 +136,7 @@ errcode_t quota_remove_inode(ext2_filsys fs, enum quota_type qtype)
        fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
        retval = ext2fs_write_bitmaps(fs);
        if (retval) {
-               log_err("Couldn't write bitmaps: %s", error_message(retval));
+               log_debug("Couldn't write bitmaps: %s", error_message(retval));
                return retval;
        }
        return 0;
@@ -170,14 +173,14 @@ errcode_t quota_write_inode(quota_ctx_t qctx, unsigned int qtype_bits)
        fs = qctx->fs;
        retval = ext2fs_get_mem(sizeof(struct quota_handle), &h);
        if (retval) {
-               log_err("Unable to allocate quota handle: %s",
+               log_debug("Unable to allocate quota handle: %s",
                        error_message(retval));
                goto out;
        }
 
        retval = ext2fs_read_bitmaps(fs);
        if (retval) {
-               log_err("Couldn't read bitmaps: %s", error_message(retval));
+               log_debug("Couldn't read bitmaps: %s", error_message(retval));
                goto out;
        }
 
@@ -191,7 +194,7 @@ errcode_t quota_write_inode(quota_ctx_t qctx, unsigned int qtype_bits)
 
                retval = quota_file_create(h, fs, qtype, fmt);
                if (retval < 0) {
-                       log_err("Cannot initialize io on quotafile");
+                       log_debug("Cannot initialize io on quotafile");
                        continue;
                }
 
@@ -202,7 +205,7 @@ errcode_t quota_write_inode(quota_ctx_t qctx, unsigned int qtype_bits)
                                strerror(errno));
                        if (h->qh_qf.e2_file)
                                ext2fs_file_close(h->qh_qf.e2_file);
-                       quota_inode_truncate(fs, h->qh_qf.ino);
+                       (void) quota_inode_truncate(fs, h->qh_qf.ino);
                        continue;
                }
 
@@ -215,7 +218,7 @@ errcode_t quota_write_inode(quota_ctx_t qctx, unsigned int qtype_bits)
 
        retval = ext2fs_write_bitmaps(fs);
        if (retval) {
-               log_err("Couldn't write bitmaps: %s", error_message(retval));
+               log_debug("Couldn't write bitmaps: %s", error_message(retval));
                goto out;
        }
 out:
@@ -245,7 +248,7 @@ static int dict_uint_cmp(const void *a, const void *b)
 
 static inline qid_t get_qid(struct ext2_inode_large *inode, enum quota_type qtype)
 {
-       int inode_size;
+       unsigned int inode_size;
 
        switch (qtype) {
        case USRQUOTA:
@@ -286,7 +289,7 @@ errcode_t quota_init_context(quota_ctx_t *qctx, ext2_filsys fs,
 
        err = ext2fs_get_mem(sizeof(struct quota_ctx), &ctx);
        if (err) {
-               log_err("Failed to allocate quota context");
+               log_debug("Failed to allocate quota context");
                return err;
        }
 
@@ -297,7 +300,7 @@ errcode_t quota_init_context(quota_ctx_t *qctx, ext2_filsys fs,
                        continue;
                err = ext2fs_get_mem(sizeof(dict_t), &dict);
                if (err) {
-                       log_err("Failed to allocate dictionary");
+                       log_debug("Failed to allocate dictionary");
                        quota_release_context(&ctx);
                        return err;
                }
@@ -586,13 +589,13 @@ errcode_t quota_update_limits(quota_ctx_t qctx, ext2_ino_t qf_ino,
 
        err = ext2fs_get_mem(sizeof(struct quota_handle), &qh);
        if (err) {
-               log_err("Unable to allocate quota handle");
+               log_debug("Unable to allocate quota handle");
                return err;
        }
 
        err = quota_file_open(qctx, qh, qf_ino, qtype, -1, 0);
        if (err) {
-               log_err("Open quota file failed");
+               log_debug("Open quota file failed");
                goto out;
        }
 
@@ -600,7 +603,7 @@ errcode_t quota_update_limits(quota_ctx_t qctx, ext2_ino_t qf_ino,
 
        err = quota_file_close(qctx, qh);
        if (err) {
-               log_err("Cannot finish IO on new quotafile: %s",
+               log_debug("Cannot finish IO on new quotafile: %s",
                        strerror(errno));
                if (qh->qh_qf.e2_file)
                        ext2fs_file_close(qh->qh_qf.e2_file);
@@ -630,7 +633,7 @@ errcode_t quota_compare_and_update(quota_ctx_t qctx, enum quota_type qtype,
 
        err = quota_file_open(qctx, &qh, 0, qtype, -1, 0);
        if (err) {
-               log_err("Open quota file failed");
+               log_debug("Open quota file failed");
                goto out;
        }
 
@@ -640,7 +643,7 @@ errcode_t quota_compare_and_update(quota_ctx_t qctx, enum quota_type qtype,
        scan_data.usage_is_inconsistent = 0;
        err = qh.qh_ops->scan_dquots(&qh, scan_dquots_callback, &scan_data);
        if (err) {
-               log_err("Error scanning dquots");
+               log_debug("Error scanning dquots");
                goto out_close_qh;
        }
 
@@ -659,7 +662,7 @@ errcode_t quota_compare_and_update(quota_ctx_t qctx, enum quota_type qtype,
 out_close_qh:
        err = quota_file_close(qctx, &qh);
        if (err) {
-               log_err("Cannot close quotafile: %s", error_message(errno));
+               log_debug("Cannot close quotafile: %s", error_message(errno));
                if (qh.qh_qf.e2_file)
                        ext2fs_file_close(qh.qh_qf.e2_file);
        }
index 0a029e2..fafdcca 100644 (file)
@@ -55,10 +55,14 @@ static int magic_library_available(void)
                if (!magic_handle)
                        return 0;
 
-               dl_magic_open = dlsym(magic_handle, "magic_open");
-               dl_magic_file = dlsym(magic_handle, "magic_file");
-               dl_magic_load = dlsym(magic_handle, "magic_load");
-               dl_magic_close = dlsym(magic_handle, "magic_close");
+               dl_magic_open = (magic_t (*)(int))
+                       dlsym(magic_handle, "magic_open");
+               dl_magic_file = (const char *(*)(magic_t, const char *))
+                       dlsym(magic_handle, "magic_file");
+               dl_magic_load = (int (*)(magic_t, const char *))
+                       dlsym(magic_handle, "magic_load");
+               dl_magic_close = (void (*)(magic_t))
+                       dlsym(magic_handle, "magic_close");
        }
 
        if (!dl_magic_open || !dl_magic_file ||
index 51a3314..ae9a2d9 100644 (file)
@@ -301,9 +301,9 @@ errout:
 }
 
 errcode_t
-profile_init(const char **files, profile_t *ret_profile)
+profile_init(const char * const *files, profile_t *ret_profile)
 {
-       const char **fs;
+       const char * const *fs;
        profile_t profile;
        prf_file_t  new_file, *last;
        errcode_t retval = 0;
index 4cc10eb..aec870a 100644 (file)
@@ -56,7 +56,7 @@ extern "C" {
 #endif /* __cplusplus */
 
 long profile_init
-       (const char * *files, profile_t *ret_profile);
+       (const char * const *files, profile_t *ret_profile);
 
 void profile_release
        (profile_t profile);
index a174784..b862326 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <et/com_err.h>
 #include "profile.h"
+#include "profile_helpers.h"
 #include "prof_err.h"
 
 /*
@@ -305,7 +306,7 @@ profile_init_path(const char * filepath,
        /* cap the array */
        filenames[i] = 0;
 
-       retval = profile_init((const char **) filenames,
+       retval = profile_init((const char * const *) filenames,
                              ret_profile);
 
        /* count back down and free the entries */
index 25c8aba..c250e31 100644 (file)
@@ -299,8 +299,11 @@ static errcode_t quota_inode_init_new(ext2_filsys fs, ext2_ino_t ino)
                return err;
        }
 
-       if (EXT2_I_SIZE(&inode))
-               quota_inode_truncate(fs, ino);
+       if (EXT2_I_SIZE(&inode)) {
+               err = quota_inode_truncate(fs, ino);
+               if (err)
+                       return err;
+       }
 
        memset(&inode, 0, sizeof(struct ext2_inode));
        ext2fs_iblk_set(fs, &inode, 0);
@@ -327,7 +330,7 @@ errcode_t quota_file_create(struct quota_handle *h, ext2_filsys fs,
                            enum quota_type qtype, int fmt)
 {
        ext2_file_t e2_file;
-       int err;
+       errcode_t err;
        ext2_ino_t qf_inum = 0;
 
        if (fmt == -1)
@@ -339,11 +342,11 @@ errcode_t quota_file_create(struct quota_handle *h, ext2_filsys fs,
                err = ext2fs_new_inode(fs, EXT2_ROOT_INO, LINUX_S_IFREG | 0600,
                                       0, &qf_inum);
                if (err)
-                       return -1;
+                       return err;
                ext2fs_inode_alloc_stats2(fs, qf_inum, +1, 0);
                ext2fs_mark_ib_dirty(fs);
        } else if (qf_inum == 0) {
-               return -1;
+               return EXT2_ET_BAD_INODE_NUM;
        }
 
        err = ext2fs_read_bitmaps(fs);
@@ -363,7 +366,7 @@ errcode_t quota_file_create(struct quota_handle *h, ext2_filsys fs,
        log_debug("Creating quota ino=%lu, type=%d", qf_inum, type);
        err = ext2fs_file_open(fs, qf_inum, h->qh_file_flags, &e2_file);
        if (err) {
-               log_err("ext2fs_file_open failed: %d", err);
+               log_err("ext2fs_file_open failed: %ld", err);
                goto out_err;
        }
        h->qh_qf.e2_file = e2_file;
@@ -376,6 +379,7 @@ errcode_t quota_file_create(struct quota_handle *h, ext2_filsys fs,
 
        if (h->qh_ops->new_io && (h->qh_ops->new_io(h) < 0)) {
                log_err("qh_ops->new_io failed");
+               err = EIO;
                goto out_err1;
        }
 
@@ -388,7 +392,7 @@ out_err:
        if (qf_inum)
                quota_inode_truncate(fs, qf_inum);
 
-       return -1;
+       return err;
 }
 
 /*
index 2a85698..3e6fd2c 100644 (file)
@@ -34,7 +34,7 @@ static inline dqbuf_t getdqbuf(void)
 /* Is given dquot empty? */
 int qtree_entry_unused(struct qtree_mem_dqinfo *info, char *disk)
 {
-       int i;
+       unsigned int i;
 
        for (i = 0; i < info->dqi_entry_size; i++)
                if (disk[i])
@@ -628,7 +628,8 @@ static int report_tree(struct dquot *dquot, unsigned int blk, int depth,
 
 static unsigned int find_set_bits(char *bmp, int blocks)
 {
-       unsigned int i, used = 0;
+       unsigned int    used = 0;
+       int             i;
 
        for (i = 0; i < blocks; i++)
                if (get_bit(bmp, i))
index 4f5d5c0..8107405 100644 (file)
@@ -2696,10 +2696,21 @@ static void fix_cluster_bg_counts(ext2_filsys fs)
 static int create_quota_inodes(ext2_filsys fs)
 {
        quota_ctx_t qctx;
+       errcode_t retval;
 
-       quota_init_context(&qctx, fs, QUOTA_ALL_BIT);
+       retval = quota_init_context(&qctx, fs, QUOTA_ALL_BIT);
+       if (retval) {
+               com_err(program_name, retval,
+                       _("while initializing quota context"));
+               exit(1);
+       }
        quota_compute_usage(qctx);
-       quota_write_inode(qctx, quotatype_bits);
+       retval = quota_write_inode(qctx, quotatype_bits);
+       if (retval) {
+               com_err(program_name, retval,
+                       _("while writing quota inodes"));
+               exit(1);
+       }
        quota_release_context(&qctx);
 
        return 0;
index 083d548..2d9ded6 100644 (file)
@@ -1479,6 +1479,7 @@ err:
 
 static void handle_quota_options(ext2_filsys fs)
 {
+       errcode_t retval;
        quota_ctx_t qctx;
        ext2_ino_t qf_ino;
        enum quota_type qtype;
@@ -1491,7 +1492,12 @@ static void handle_quota_options(ext2_filsys fs)
                /* Nothing to do. */
                return;
 
-       quota_init_context(&qctx, fs, QUOTA_ALL_BIT);
+       retval = quota_init_context(&qctx, fs, QUOTA_ALL_BIT);
+       if (retval) {
+               com_err(program_name, retval,
+                       _("while initializing quota context in support library"));
+               exit(1);
+       }
        for (qtype = 0 ; qtype < MAXQUOTAS; qtype++) {
                if (quota_enable[qtype] == QOPT_ENABLE) {
                        enable = 1;
@@ -1504,11 +1510,31 @@ static void handle_quota_options(ext2_filsys fs)
        for (qtype = 0 ; qtype < MAXQUOTAS; qtype++) {
                if (quota_enable[qtype] == QOPT_ENABLE &&
                    *quota_sb_inump(fs->super, qtype) == 0) {
-                       if ((qf_ino = quota_file_exists(fs, qtype)) > 0)
-                               quota_update_limits(qctx, qf_ino, qtype);
-                       quota_write_inode(qctx, 1 << qtype);
+                       if ((qf_ino = quota_file_exists(fs, qtype)) > 0) {
+                               retval = quota_update_limits(qctx, qf_ino,
+                                                            qtype);
+                               if (retval) {
+                                       com_err(program_name, retval,
+                                               _("while updating quota limits (%d)"),
+                                               qtype);
+                                       exit(1);
+                               }
+                       }
+                       retval = quota_write_inode(qctx, 1 << qtype);
+                       if (retval) {
+                               com_err(program_name, retval,
+                                       _("while writing quota file (%d)"),
+                                       qtype);
+                               exit(1);
+                       }
                } else if (quota_enable[qtype] == QOPT_DISABLE) {
-                       quota_remove_inode(fs, qtype);
+                       retval = quota_remove_inode(fs, qtype);
+                       if (retval) {
+                               com_err(program_name, retval,
+                                       _("while removing quota file (%d)"),
+                                       qtype);
+                               exit(1);
+                       }
                }
        }