Whamcloud - gitweb
LU-12593 osd: up i_append_sem during errors 45/37445/3
authorAlexander Boyko <c17825@cray.com>
Mon, 3 Feb 2020 09:24:40 +0000 (04:24 -0500)
committerOleg Drokin <green@whamcloud.com>
Sat, 8 Feb 2020 05:35:32 +0000 (05:35 +0000)
There is a potential leak of i_append_sem during errors for
buffer head read and ldiskfs_joural_get_write_access() at
osd_ldiskfs_write_record().
The patch adds up(i_append_sem) for errors paths.

Lustre-change: https://review.whamcloud.com/37406/
Lustre-commit: 7599dd3d20d6bb4ee89634c5a76730481ca62470

Fixes: f832a7dc33c6 ("LU-12593 osd: zeroing a freshly allocated block buffer")
Signed-off-by: Alexander Boyko <c17825@cray.com>
Change-Id: I245d0c45af03519c66b75731e5d57f42de41fe95
Signed-off-by: Minh Diep <mdiep@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/37445
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/osd-ldiskfs/osd_io.c

index a8f69bc..585f086 100644 (file)
@@ -2049,7 +2049,7 @@ static int osd_ldiskfs_write_record(struct dt_object *dt, void *buf,
         int                 boffs;
         int                 dirty_inode = 0;
        struct ldiskfs_inode_info *ei = LDISKFS_I(inode);
-       bool create, sparse;
+       bool create, sparse, sync = false;
 
        if (write_NUL) {
                /*
@@ -2067,7 +2067,6 @@ static int osd_ldiskfs_write_record(struct dt_object *dt, void *buf,
 
        while (bufsize > 0) {
                int credits = handle->h_buffer_credits;
-               bool sync;
                unsigned long last_block = (new_size == 0) ? 0 :
                                           (new_size - 1) >> inode->i_blkbits;
 
@@ -2104,8 +2103,10 @@ static int osd_ldiskfs_write_record(struct dt_object *dt, void *buf,
                        bh = __ldiskfs_bread(handle, inode, block, flags);
                        create = true;
                } else {
-                       if (sync)
+                       if (sync) {
                                up(&ei->i_append_sem);
+                               sync = false;
+                       }
                        create = false;
                }
                if (IS_ERR_OR_NULL(bh)) {
@@ -2134,8 +2135,10 @@ static int osd_ldiskfs_write_record(struct dt_object *dt, void *buf,
                         boffs, size, (unsigned long)bh->b_size);
                if (create) {
                        memset(bh->b_data, 0, bh->b_size);
-                       if (sync)
+                       if (sync) {
                                up(&ei->i_append_sem);
+                               sync = false;
+                       }
                }
                memcpy(bh->b_data + boffs, buf, size);
                err = ldiskfs_handle_dirty_metadata(handle, NULL, bh);
@@ -2148,8 +2151,11 @@ static int osd_ldiskfs_write_record(struct dt_object *dt, void *buf,
                 bufsize -= size;
                 buf += size;
         }
-        if (bh)
-                brelse(bh);
+       if (sync)
+               up(&ei->i_append_sem);
+
+       if (bh)
+               brelse(bh);
 
        if (write_NUL)
                --new_size;