Whamcloud - gitweb
LU-3365 lmv: support DNE with HSM.
[fs/lustre-release.git] / lustre / utils / llverfs.c
index 0ecf8f2..87c9a9c 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -28,6 +26,8 @@
 /*
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -527,6 +527,7 @@ static int dir_write(char *chunk_buf, size_t chunksize,
        struct timeval start_time;
        unsigned long long total_bytes;
        unsigned long long curr_bytes = 0;
+       int rc = 0;
 
 #ifdef HAVE_EXT2FS_EXT2FS_H
        if (!full && fsetflags(testdir, EXT2_TOPDIR_FL))
@@ -545,7 +546,8 @@ static int dir_write(char *chunk_buf, size_t chunksize,
            fflush(countfile) != 0) {
                fprintf(stderr, "\n%s: writing %s failed :%s\n",
                        progname, filecount, strerror(errno));
-               return 6;
+               rc = 6;
+               goto out;
        }
 
        /* calculate total bytes that need to be written */
@@ -553,7 +555,8 @@ static int dir_write(char *chunk_buf, size_t chunksize,
        if (total_bytes <= 0) {
                fprintf(stderr, "\n%s: unable to calculate total bytes\n",
                        progname);
-               return 7;
+               rc = 7;
+               goto out;
        }
 
        if (!full && (dir_num != 0))
@@ -575,7 +578,8 @@ static int dir_write(char *chunk_buf, size_t chunksize,
                                        fprintf(stderr, "\n%s: mkdir %s : %s\n",
                                                progname, tempdir,
                                                strerror(errno));
-                                       return 1;
+                                       rc = 1;
+                                       goto out;
                                }
                        }
                        dir_num++;
@@ -600,8 +604,10 @@ static int dir_write(char *chunk_buf, size_t chunksize,
                                   time_st, inode_st, tempfile);
                close(fd);
                if (ret < 0) {
-                       if (ret != -ENOSPC)
-                               return 1;
+                       if (ret != -ENOSPC) {
+                               rc = 1;
+                               goto out;
+                       }
                        curr_bytes = total_bytes;
                        break;
                }
@@ -618,7 +624,6 @@ static int dir_write(char *chunk_buf, size_t chunksize,
                                progname, filecount, strerror(errno));
                }
        }
-       fclose(countfile);
 
        if (verbose) {
                verbose++;
@@ -628,7 +633,10 @@ static int dir_write(char *chunk_buf, size_t chunksize,
                verbose--;
        }
 
-       return 0;
+out:
+       fclose(countfile);
+
+       return rc;
 }
 
 /*
@@ -861,7 +869,8 @@ guess:
                fprintf(stderr, "Memory allocation failed for chunk_buf\n");
                return 4;
        }
-       sprintf(filecount, "%s/%s.filecount", testdir, progname);
+       snprintf(filecount, sizeof(filecount), "%s/%s.filecount",
+                testdir, progname);
        if (writeoption) {
                (void)mkdir(testdir, dirmode);