Print this page
15291 zfs-tests errno flaws exposed by 15220

Split Close
Expand all
Collapse all
          --- old/usr/src/test/zfs-tests/cmd/file_write/file_write.c
          +++ new/usr/src/test/zfs-tests/cmd/file_write/file_write.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   */
  26   26  
       27 +/*
       28 + * Copyright 2022 MNX Cloud, Inc.
       29 + */
       30 +
  27   31  #include "../file_common.h"
  28   32  #include <libgen.h>
  29   33  
  30   34  static unsigned char bigbuffer[BIGBUFFERSIZE];
  31   35  
  32   36  /*
  33   37   * Writes (or appends) a given value to a file repeatedly.
  34   38   * See header file for defaults.
  35   39   */
  36   40  
↓ open down ↓ 15 lines elided ↑ open up ↑
  52   56           */
  53   57          int             write_count = BIGFILESIZE;
  54   58          uchar_t         fillchar = DATA;
  55   59          int             block_size = BLOCKSZ;
  56   60          char            *filename = NULL;
  57   61          char            *operation = NULL;
  58   62          offset_t        noffset, offset = 0;
  59   63          int             verbose = 0;
  60   64          int             rsync = 0;
  61   65          int             wsync = 0;
       66 +        int             exitcode;
  62   67  
  63   68          /*
  64   69           * Process Arguments
  65   70           */
  66   71          while ((c = getopt(argc, argv, "b:c:d:s:f:o:vwr")) != -1) {
  67   72                  switch (c) {
  68   73                          case 'b':
  69   74                                  block_size = atoi(optarg);
  70   75                                  break;
  71   76                          case 'c':
↓ open down ↓ 87 lines elided ↑ open up ↑
 159  164  
 160  165          if (wsync) {
 161  166                  oflag = oflag | O_SYNC;
 162  167          }
 163  168  
 164  169          /*
 165  170           * Given an operation (create/overwrite/append), open the file
 166  171           * accordingly and perform a write of the appropriate type.
 167  172           */
 168  173          if ((bigfd = open(filename, oflag, 0666)) == -1) {
      174 +                exitcode = errno;
 169  175                  (void) printf("open %s: failed [%s]%d. Aborting!\n", filename,
 170  176                      strerror(errno), errno);
 171      -                exit(errno);
      177 +                exit(exitcode);
 172  178          }
 173  179          noffset = llseek(bigfd, offset, SEEK_SET);
 174  180          if (noffset != offset) {
      181 +                exitcode = errno;
 175  182                  (void) printf("llseek %s (%lld/%lld) failed [%s]%d.Aborting!\n",
 176  183                      filename, offset, noffset, strerror(errno), errno);
 177      -                exit(errno);
      184 +                exit(exitcode);
 178  185          }
 179  186  
 180  187          if (verbose) {
 181  188                  (void) printf("%s: block_size = %d, write_count = %d, "
 182  189                      "offset = %lld, data = %s%d\n", filename, block_size,
 183  190                      write_count, offset,
 184  191                      (fillchar == 0) ? "0->" : "",
 185  192                      (fillchar == 0) ? DATA_RANGE : fillchar);
 186  193          }
 187  194  
 188  195          for (i = 0; i < write_count; i++) {
 189  196                  ssize_t n;
 190  197  
 191  198                  if ((n = write(bigfd, &bigbuffer, block_size)) == -1) {
      199 +                        exitcode = errno;
 192  200                          (void) printf("write failed (%ld), good_writes = %lld, "
 193  201                              "error: %s[%d]\n", (long)n, good_writes,
 194  202                              strerror(errno),
 195  203                              errno);
 196      -                        exit(errno);
      204 +                        exit(exitcode);
 197  205                  }
 198  206                  good_writes++;
 199  207          }
 200  208  
 201  209          if (verbose) {
 202  210                  (void) printf("Success: good_writes = %lld (%lld)\n",
 203  211                      good_writes, (good_writes * block_size));
 204  212          }
 205  213  
 206  214          return (0);
↓ open down ↓ 25 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX