]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libsupport: fix error handling in quota_write_inode
authorzhangyi (F) <yi.zhang@huawei.com>
Mon, 24 Jul 2017 07:01:26 +0000 (15:01 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 24 Jul 2017 19:15:39 +0000 (15:15 -0400)
The error return value of quota_file_create() is no longer < 0,
and the error handling in quota_write_inode() is incorrect,
fix these. This also fix a tune2fs segfault that currently
occurs when we add project and quota features to an inode
exhaustion ext4 filesystem.

Fixes: a701823a3150("libsupport: fix gcc -Wall nits")
Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/support/mkquota.c
lib/support/quotaio.c

index 11a878e7f1315785e42f9262381d90913db60f51..00f3a406e76e98b8fe786e710bbd2dcbaffa7cb5 100644 (file)
@@ -193,20 +193,21 @@ errcode_t quota_write_inode(quota_ctx_t qctx, unsigned int qtype_bits)
                        continue;
 
                retval = quota_file_create(h, fs, qtype, fmt);
-               if (retval < 0) {
-                       log_debug("Cannot initialize io on quotafile");
-                       continue;
+               if (retval) {
+                       log_debug("Cannot initialize io on quotafile: %s",
+                                 error_message(retval));
+                       goto out;
                }
 
                write_dquots(dict, h);
                retval = quota_file_close(qctx, h);
-               if (retval < 0) {
-                       log_err("Cannot finish IO on new quotafile: %s",
-                               strerror(errno));
+               if (retval) {
+                       log_debug("Cannot finish IO on new quotafile: %s",
+                                 strerror(errno));
                        if (h->qh_qf.e2_file)
                                ext2fs_file_close(h->qh_qf.e2_file);
                        (void) quota_inode_truncate(fs, h->qh_qf.ino);
-                       continue;
+                       goto out;
                }
 
                /* Set quota inode numbers in superblock. */
index 240eab3d63ea234ac3c273c64c7c963e078a0dce..2daf17858c12f4b63a6112a0c6205574eb1374e0 100644 (file)
@@ -273,11 +273,13 @@ errcode_t quota_file_open(quota_ctx_t qctx, struct quota_handle *h,
        if (h->qh_ops->check_file &&
            (h->qh_ops->check_file(h, qtype, fmt) == 0)) {
                log_err("qh_ops->check_file failed");
+               err = EIO;
                goto errout;
        }
 
        if (h->qh_ops->init_io && (h->qh_ops->init_io(h) < 0)) {
                log_err("qh_ops->init_io failed");
+               err = EIO;
                goto errout;
        }
        if (allocated_handle)
@@ -288,7 +290,7 @@ errout:
        ext2fs_file_close(e2_file);
        if (allocated_handle)
                ext2fs_free_mem(&h);
-       return -1;
+       return err;
 }
 
 static errcode_t quota_inode_init_new(ext2_filsys fs, ext2_ino_t ino)
@@ -405,12 +407,12 @@ errcode_t quota_file_close(quota_ctx_t qctx, struct quota_handle *h)
 {
        if (h->qh_io_flags & IOFL_INFODIRTY) {
                if (h->qh_ops->write_info && h->qh_ops->write_info(h) < 0)
-                       return -1;
+                       return EIO;
                h->qh_io_flags &= ~IOFL_INFODIRTY;
        }
 
        if (h->qh_ops->end_io && h->qh_ops->end_io(h) < 0)
-               return -1;
+               return EIO;
        if (h->qh_qf.e2_file) {
                __u64 new_size, size;