xfs
[Top] [All Lists]

[PATCH 3/3] xfs_fsr: test for more potential failures in packfile()

To: Eric Sandeen <sandeen@xxxxxxxxxx>, xfs-oss <xfs@xxxxxxxxxxx>
Subject: [PATCH 3/3] xfs_fsr: test for more potential failures in packfile()
From: Eric Sandeen <sandeen@xxxxxxxxxxx>
Date: Fri, 06 Jun 2014 16:06:47 -0500
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <53922B49.1050005@xxxxxxxxxx>
References: <53922B49.1050005@xxxxxxxxxx>
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
Test for lseek, ftruncate, and fsync failures in packfile()

Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
---

diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
index 8b191e6..48629fd 100644
--- a/fsr/xfs_fsr.c
+++ b/fsr/xfs_fsr.c
@@ -1325,7 +1325,11 @@ packfile(char *fname, char *tname, int fd,
                                fsrprintf(_("could not trunc tmp %s\n"),
                                           tname);
                        }
-                       lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR);
+                       if (lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR) < 
0) {
+                               fsrprintf(_("could not lseek in tmpfile: %s : 
%s\n"),
+                                  tname, strerror(errno));
+                               goto out;
+                       }
                        continue;
                } else if (outmap[extent].bmv_length == 0) {
                        /* to catch holes at the beginning of the file */
@@ -1341,7 +1345,11 @@ packfile(char *fname, char *tname, int fd,
                                        " %s\n"), tname);
                                goto out;
                        }
-                       lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR);
+                       if (lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR) < 
0) {
+                               fsrprintf(_("could not lseek in tmpfile: %s : 
%s\n"),
+                                  tname, strerror(errno));
+                               goto out;
+                       }
                }
        } /* end of space allocation loop */
 
@@ -1365,8 +1373,16 @@ packfile(char *fname, char *tname, int fd,
        for (extent = 0; extent < nextents; extent++) {
                pos = outmap[extent].bmv_offset;
                if (outmap[extent].bmv_block == -1) {
-                       lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR);
-                       lseek64(fd, outmap[extent].bmv_length, SEEK_CUR);
+                       if (lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR) < 
0) {
+                               fsrprintf(_("could not lseek in tmpfile: %s : 
%s\n"),
+                                  tname, strerror(errno));
+                               goto out;
+                       }
+                       if (lseek64(fd, outmap[extent].bmv_length, SEEK_CUR) < 
0) {
+                               fsrprintf(_("could not lseek in file: %s : 
%s\n"),
+                                  fname, strerror(errno));
+                               goto out;
+                       }
                        continue;
                } else if (outmap[extent].bmv_length == 0) {
                        /* to catch holes at the beginning of the file */
@@ -1442,8 +1458,16 @@ packfile(char *fname, char *tname, int fd,
                        }
                }
        }
-       ftruncate64(tfd, statp->bs_size);
-       fsync(tfd);
+       if (ftruncate64(tfd, statp->bs_size) < 0) {
+               fsrprintf(_("could not truncate tmpfile: %s : %s\n"),
+                               fname, strerror(errno));
+               goto out;
+       }
+       if (fsync(tfd) < 0) {
+               fsrprintf(_("could not fsync tmpfile: %s : %s\n"),
+                               fname, strerror(errno));
+               goto out;
+       }
 
        sx.sx_stat     = *statp; /* struct copy */
        sx.sx_version  = XFS_SX_VERSION;

<Prev in Thread] Current Thread [Next in Thread>