xfs_io: set exitcode on failure appropriately
RFC PATCH 1/1 xfs_io: set exitcode on failure appropriately
From: Dave Chinner <[email protected]>
Many operations don't set the exitcode when they fail, resulting in xfs_io exiting with a zero (no failure) exit code despite the command failing and returning an error. The command return code is really a boolean to tell the libxcmd command loop whether to continue processing or not, while exitcode is the actual xfs_io exit code returned to the parent on exit.
This patchset just makes the code do the right thing. It's not the nicest code, but it's a start at producing correct behaviour.
Signed-off-by Dave Chinner <[email protected]>
--- io/attr.c | 18 +++++++--- io/copy_file_range.c | 13 +++++-- io/cowextsize.c | 5 +++ io/encrypt.c | 11 +++++- io/fadvise.c | 9 ++++- io/fiemap.c | 3 ++ io/file.c | 1 + io/fsmap.c | 9 +++-- io/fsync.c | 2 ++ io/getrusage.c | 1 + io/imap.c | 4 ++- io/inject.c | 1 + io/link.c | 1 + io/log_writes.c | 7 ++-- io/madvise.c | 10 +++++- io/mincore.c | 10 +++++- io/mmap.c | 63 ++++++++++++++++++++++++++------ io/open.c | 85 ++++++++++++++++++++++++++++++++------------ io/parent.c | 1 + io/pread.c | 19 ++++++++-- io/prealloc.c | 57 +++++++++++++++++++++++------ io/pwrite.c | 31 +++++++++++++--- io/readdir.c | 10 ++++-- io/reflink.c | 30 +++++++++++++--- io/resblks.c | 3 ++ io/seek.c | 12 +++++-- io/sendfile.c | 18 ++++++++-- io/shutdown.c | 2 ++ io/stat.c | 13 ++++++- io/sync_file_range.c | 8 ++++- io/truncate.c | 2 ++ io/utimes.c | 3 ++ 32 files changed, 378 insertions(+), 84 deletions(-)
io/attr.c +14 -4
@@ -175,10 +175,11 @@ lsattr_callback(if ((fd =open (path,O_RDONLY )) ==-1 )fprintf (stderr,_ ("%s: cannot open %s: %s\n" ), progname, path,strerror (errno)); -else if ((xfsctl (path, fd,FS_IOC_FSGETXATTR , &fsx)) <0 ) +else if ((xfsctl (path, fd,FS_IOC_FSGETXATTR , &fsx)) <0 ) {fprintf (stderr,_ ("%s: cannot get flags on %s: %s\n" ), progname, path,strerror (errno)); -else + exitcode =1 ; + }else printxattr (fsx.fsx_xflags,0 ,1 , path,0 ,1 );if (fd !=-1 )
@@ -225,6 +226,7 @@ lsattr_f( }else if ((xfsctl (name, file->fd,FS_IOC_FSGETXATTR , &fsx)) <0 ) {fprintf (stderr,_ ("%s: cannot get flags on %s: %s\n" ), progname, name,strerror (errno)); + exitcode =1 ; }else {printxattr (fsx.fsx_xflags, vflag, !aflag, name, vflag, !aflag);if (aflag) {
@@ -257,9 +259,11 @@ chattr_callback( }else { attr.fsx_xflags |= orflags; attr.fsx_xflags &= ~andflags; -if (xfsctl (path, fd,FS_IOC_FSSETXATTR , &attr) <0 ) +if (xfsctl (path, fd,FS_IOC_FSSETXATTR , &attr) <0 ) {fprintf (stderr,_ ("%s: cannot set flags on %s: %s\n" ), progname, path,strerror (errno)); + exitcode =1 ; + } }if (fd !=-1 )
@@ -295,6 +299,7 @@ chattr_f(if (!p->flag) {fprintf (stderr,_ ("%s: unknown flag\n" ), progname); + exitcode =1 ;return 0 ; } }
@@ -309,12 +314,14 @@ chattr_f(if (!p->flag) {fprintf (stderr,_ ("%s: unknown flag\n" ), progname); + exitcode =1 ;return 0 ; } } }else {fprintf (stderr,_ ("%s: bad chattr command, not +/-X\n" ), progname); + exitcode =1 ;return 0 ; } }
@@ -325,12 +332,15 @@ chattr_f( }else if (xfsctl (name, file->fd,FS_IOC_FSGETXATTR , &attr) <0 ) {fprintf (stderr,_ ("%s: cannot get flags on %s: %s\n" ), progname, name,strerror (errno)); + exitcode =1 ; }else { attr.fsx_xflags |= orflags; attr.fsx_xflags &= ~andflags; -if (xfsctl (name, file->fd,FS_IOC_FSSETXATTR , &attr) <0 ) +if (xfsctl (name, file->fd,FS_IOC_FSSETXATTR , &attr) <0 ) {fprintf (stderr,_ ("%s: cannot set flags on %s: %s\n" ), progname, name,strerror (errno)); + exitcode =1 ; + } }return 0 ; }
io/copy_file_range.c +11 -2
@@ -103,6 +103,7 @@ copy_range_f(int argc, char **argv) src =strtoull (optarg, &sp,10 );if (!sp || sp == optarg) {printf (_ ("invalid source offset -- %s\n" ), sp); + exitcode =1 ;return 0 ; }break ;
@@ -110,6 +111,7 @@ copy_range_f(int argc, char **argv) dst =strtoull (optarg, &sp,10 );if (!sp || sp == optarg) {printf (_ ("invalid destination offset -- %s\n" ), sp); + exitcode =1 ;return 0 ; }break ;
@@ -117,18 +119,23 @@ copy_range_f(int argc, char **argv) len =strtoull (optarg, &sp,10 );if (!sp || sp == optarg) {printf (_ ("invalid length -- %s\n" ), sp); + exitcode =1 ;return 0 ; }break ; } } -if (optind != argc -1 ) +if (optind != argc -1 ) { + exitcode =1 ;return command_usage (©_range_cmd); + } fd =openfile (argv[optind],NULL ,IO_READONLY ,0 ,NULL ); -if (fd <0 ) +if (fd <0 ) { + exitcode =1 ;return 0 ; + }if (src ==0 && dst ==0 && len ==0 ) { len =copy_src_filesize (fd);
@@ -137,6 +144,8 @@ copy_range_f(int argc, char **argv) ret =copy_file_range_cmd (fd, &src, &dst, len);close (fd); +if (ret <0 ) + exitcode =1 ;return ret; }
io/cowextsize.c +5 -0
@@ -53,6 +53,7 @@ get_cowextsize(const char *path, int fd)if ((xfsctl (path, fd,FS_IOC_FSGETXATTR , &fsx)) <0 ) {printf ("%s: XFS_IOC_FSGETXATTR %s: %s\n" , progname, path,strerror (errno)); + exitcode =1 ;return 0 ; }printf ("[%u] %s\n" , fsx.fsx_cowextsize, path);
@@ -67,11 +68,13 @@ set_cowextsize(const char *path, int fd, long extsz)if (fstat64 (fd, &stat) <0 ) {perror ("fstat64" ); + exitcode =1 ;return 0 ; }if ((xfsctl (path, fd,FS_IOC_FSGETXATTR , &fsx)) <0 ) {printf ("%s: XFS_IOC_FSGETXATTR %s: %s\n" , progname, path,strerror (errno)); + exitcode =1 ;return 0 ; }
@@ -86,6 +89,7 @@ set_cowextsize(const char *path, int fd, long extsz)if ((xfsctl (path, fd,FS_IOC_FSSETXATTR , &fsx)) <0 ) {printf ("%s: XFS_IOC_FSSETXATTR %s: %s\n" , progname, path,strerror (errno)); + exitcode =1 ;return 0 ; }
@@ -168,6 +172,7 @@ cowextsize_f(if (cowextsize <0 ) {printf (_ ("non-numeric cowextsize argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; } }else {
io/encrypt.c +10 -1
@@ -205,6 +205,7 @@ set_encpolicy_f(int argc, char **argv) &policy.contents_encryption_mode)) {fprintf (stderr,"invalid contents encryption " "mode: %s\n" , optarg); + exitcode =1 ;return 0 ; }break ;
@@ -213,12 +214,14 @@ set_encpolicy_f(int argc, char **argv) &policy.filenames_encryption_mode)) {fprintf (stderr,"invalid filenames encryption " "mode: %s\n" , optarg); + exitcode =1 ;return 0 ; }break ;case 'f' :if (!parse_byte_value (optarg, &policy.flags)) {fprintf (stderr,"invalid flags: %s\n" , optarg); + exitcode =1 ;return 0 ; }break ;
@@ -226,18 +229,22 @@ set_encpolicy_f(int argc, char **argv)if (!parse_byte_value (optarg, &policy.version)) {fprintf (stderr,"invalid policy version: %s\n" , optarg); + exitcode =1 ;return 0 ; }break ;default : + exitcode =1 ;return command_usage (&set_encpolicy_cmd); } } argc -= optind; argv += optind; -if (argc >1 ) +if (argc >1 ) { + exitcode =1 ;return command_usage (&set_encpolicy_cmd); + }/* Parse key descriptor if specified */ if (argc >0 ) {
@@ -249,6 +256,7 @@ set_encpolicy_f(int argc, char **argv)if (strlen (keydesc) !=FS_KEY_DESCRIPTOR_SIZE *2 ) {fprintf (stderr,"invalid key descriptor: %s\n" , keydesc); + exitcode =1 ;return 0 ; }
@@ -256,6 +264,7 @@ set_encpolicy_f(int argc, char **argv)if (tmp == keydesc || *tmp !='\0' ) {fprintf (stderr,"invalid key descriptor: %s\n" , keydesc); + exitcode =1 ;return 0 ; }
io/fadvise.c +8 -1
@@ -77,19 +77,23 @@ fadvise_f( range =1 ;break ;default : + exitcode =1 ;return command_usage (&fadvise_cmd); } }if (range) {size_t blocksize, sectsize; -if (optind != argc -2 ) +if (optind != argc -2 ) { + exitcode =1 ;return command_usage (&fadvise_cmd); + }init_cvtnum (&blocksize, §size); offset =cvtnum (blocksize, sectsize, argv[optind]);if (offset <0 ) {printf (_ ("non-numeric offset argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; } optind++;
@@ -97,14 +101,17 @@ fadvise_f(if (length <0 ) {printf (_ ("non-numeric length argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; } }else if (optind != argc) { + exitcode =1 ;return command_usage (&fadvise_cmd); }if (posix_fadvise (file->fd, offset, length, advise) <0 ) {perror ("fadvise" ); + exitcode =1 ;return 0 ; }return 0 ;
io/fiemap.c +3 -0
@@ -269,6 +269,7 @@ fiemap_f( vflag++;break ;default : + exitcode =1 ;return command_usage (&fiemap_cmd); } }
@@ -278,6 +279,7 @@ fiemap_f( start_offset =cvtnum (fsblocksize, fssectsize, argv[optind]);if (start_offset <0 ) {printf ("non-numeric offset argument -- %s\n" , argv[optind]); + exitcode =1 ;return 0 ; } last_logical = start_offset;
@@ -289,6 +291,7 @@ fiemap_f( length =cvtnum (fsblocksize, fssectsize, argv[optind]);if (length <0 ) {printf ("non-numeric len argument -- %s\n" , argv[optind]); + exitcode =1 ;return 0 ; } range_end = start_offset + length;
io/file.c +1 -0
@@ -79,6 +79,7 @@ file_f( i =atoi (argv[1 ]);if (i <0 || i >= filecount) {printf (_ ("value %d is out of range (0-%d)\n" ), i, filecount-1 ); + exitcode =1 ; }else { file = &filetable[i];filelist_f ();
io/fsmap.c +7 -2
@@ -430,13 +430,16 @@ fsmap_f( vflag++;break ;default : + exitcode =1 ;return command_usage (&fsmap_cmd); } }if ((dflag + lflag + rflag >1 ) || (mflag >0 && vflag >0 ) || - (argc > optind && dflag + lflag + rflag ==0 )) + (argc > optind && dflag + lflag + rflag ==0 )) { + exitcode =1 ;return command_usage (&fsmap_cmd); + }if (argc > optind) { start =cvtnum (fsblocksize, fssectsize, argv[optind]);
@@ -444,6 +447,7 @@ fsmap_f(fprintf (stderr,_ ("Bad rmap start_bblock %s.\n" ), argv[optind]); + exitcode =1 ;return 0 ; } start <<=BBSHIFT ;
@@ -455,6 +459,7 @@ fsmap_f(fprintf (stderr,_ ("Bad rmap end_bblock %s.\n" ), argv[optind +1 ]); + exitcode =1 ;return 0 ; } end <<=BBSHIFT ;
@@ -508,8 +513,8 @@ fsmap_f( " iflags=0x%x [\"%s\"]: %s\n"), progname, head->fmh_iflags, file->name, strerror(errno)); -free (head); exitcode =1 ; +free (head);return 0 ; }if (head->fmh_entries > map_size +2 ) {
io/fsync.c +2 -0
@@ -31,6 +31,7 @@ fsync_f( {if (fsync (file->fd) <0 ) {perror ("fsync" ); + exitcode =1 ;return 0 ; }return 0 ;
@@ -43,6 +44,7 @@ fdatasync_f( {if (fdatasync (file->fd) <0 ) {perror ("fdatasync" ); + exitcode =1 ;return 0 ; }return 0 ;
io/getrusage.c +1 -0
@@ -62,6 +62,7 @@ getrusage_f(if (getrusage (RUSAGE_SELF , &rusage) <0 ) {perror ("getrusage" ); + exitcode =1 ;return 0 ; }
io/imap.c +3 -1
@@ -39,8 +39,10 @@ imap_f(int argc, char **argv) nent =atoi (argv[1 ]); t =malloc (nent *sizeof (*t)); -if (!t) +if (!t) { + exitcode =1 ;return 0 ; + } bulkreq.lastip = &last; bulkreq.icount = nent;
io/inject.c +1 -0
@@ -129,6 +129,7 @@ inject_f( command =XFS_IOC_ERROR_CLEARALL ;if ((xfsctl (file->name, file->fd, command, &error)) <0 ) {perror ("XFS_IOC_ERROR_INJECTION" ); + exitcode =1 ;continue ; } }
io/link.c +1 -0
@@ -47,6 +47,7 @@ flink_f(if (linkat (file->fd,"" ,AT_FDCWD , argv[1 ],AT_EMPTY_PATH ) <0 ) {perror ("flink" ); + exitcode =1 ;return 0 ; }return 0 ;
io/log_writes.c +4 -3
@@ -65,7 +65,6 @@ log_writes_f(const char *mark =NULL ;int c; - exitcode =1 ;while ((c =getopt (argc, argv,"d:m:" )) !=EOF ) {switch (c) {case 'd' :
@@ -75,15 +74,17 @@ log_writes_f( mark = optarg;break ;default : + exitcode =1 ;return command_usage (&log_writes_cmd); } } -if (device ==NULL || mark ==NULL ) +if (device ==NULL || mark ==NULL ) { + exitcode =1 ;return command_usage (&log_writes_cmd); + }if (mark_log (device, mark)) - exitcode =0 ;return 0 ; }
io/madvise.c +9 -1
@@ -72,6 +72,7 @@ madvise_f( advise =MADV_WILLNEED ;break ;default : + exitcode =1 ;return command_usage (&madvise_cmd); } }
@@ -85,6 +86,7 @@ madvise_f(if (offset <0 ) {printf (_ ("non-numeric offset argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; } optind++;
@@ -92,23 +94,29 @@ madvise_f(if (llength <0 ) {printf (_ ("non-numeric length argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; }else if (llength > (size_t )llength) {printf (_ ("length argument too large -- %lld\n" ), (long long )llength); + exitcode =1 ;return 0 ; }else length = (size_t )llength; }else { + exitcode =1 ;return command_usage (&madvise_cmd); } start =check_mapping_range (mapping, offset, length,1 ); -if (!start) +if (!start) { + exitcode =1 ;return 0 ; + }if (madvise (start, length, advise) <0 ) {perror ("madvise" ); + exitcode =1 ;return 0 ; }return 0 ;
io/mincore.c +9 -1
@@ -46,36 +46,44 @@ mincore_f(if (offset <0 ) {printf (_ ("non-numeric offset argument -- %s\n" ), argv[1 ]); + exitcode =1 ;return 0 ; } llength =cvtnum (blocksize, sectsize, argv[2 ]);if (llength <0 ) {printf (_ ("non-numeric length argument -- %s\n" ), argv[2 ]); + exitcode =1 ;return 0 ; }else if (llength > (size_t )llength) {printf (_ ("length argument too large -- %lld\n" ), (long long )llength); + exitcode =1 ;return 0 ; }else length = (size_t )llength; }else { + exitcode =1 ;return command_usage (&mincore_cmd); } start =check_mapping_range (mapping, offset, length,1 ); -if (!start) +if (!start) { + exitcode =1 ;return 0 ; + } vec =calloc (length/pagesize,sizeof (unsigned char ));if (!vec) {perror ("calloc" ); + exitcode =1 ;return 0 ; }if (mincore (start, length, vec) <0 ) {perror ("mincore" );free (vec); + exitcode =1 ;return 0 ; }
io/mmap.c +52 -11
243 lines not on this page · raw message
io/open.c +63 -22
263 lines not on this page · raw message
io/parent.c +1 -0
@@ -387,6 +387,7 @@ parent_f(int argc, char **argv)if (!fs) {fprintf (stderr,_ ("file argument, \"%s\", is not in a mounted XFS filesystem\n" ), file->name); + exitcode =1 ;return 1 ; } mntpt = fs->fs_dir;
io/pread.c +16 -3
@@ -400,6 +400,7 @@ pread_f( tmp =cvtnum (fsblocksize, fssectsize, optarg);if (tmp <0 ) {printf (_ ("non-numeric bsize -- %s\n" ), optarg); + exitcode =1 ;return 0 ; } bsize = tmp;
@@ -431,6 +432,7 @@ pread_f(if (!sp || sp == optarg) {printf (_ ("non-numeric vector count == %s\n" ), optarg); + exitcode =1 ;return 0 ; }break ;
@@ -439,21 +441,26 @@ pread_f( zeed =strtoul (optarg, &sp,0 );if (!sp || sp == optarg) {printf (_ ("non-numeric seed -- %s\n" ), optarg); + exitcode =1 ;return 0 ; }break ;default : + exitcode =1 ;return command_usage (&pread_cmd); } } -if (optind != argc -2 ) +if (optind != argc -2 ) { + exitcode =1 ;return command_usage (&pread_cmd); + } offset =cvtnum (fsblocksize, fssectsize, argv[optind]);if (offset <0 && (direction & (IO_RANDOM |IO_BACKWARD ))) { eof =-1 ;/* read from EOF */ }else if (offset <0 ) {printf (_ ("non-numeric length argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; } optind++;
@@ -462,11 +469,14 @@ pread_f( eof =-1 ;/* read to EOF */ }else if (count <0 ) {printf (_ ("non-numeric length argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; } -if (alloc_buffer (bsize, uflag,0xabababab ) <0 ) +if (alloc_buffer (bsize, uflag,0xabababab ) <0 ) { + exitcode =1 ;return 0 ; + }gettimeofday (&t1,NULL );switch (direction) {
@@ -486,8 +496,11 @@ pread_f(default :ASSERT (0 ); } -if (c <0 ) +if (c <0 ) { + exitcode =1 ;return 0 ; + } +if (qflag)return 0 ;gettimeofday (&t2,NULL );
io/prealloc.c +46 -11
178 lines not on this page · raw message
io/pwrite.c +26 -5
@@ -308,6 +308,7 @@ pwrite_f( tmp =cvtnum (fsblocksize, fssectsize, optarg);if (tmp <0 ) {printf (_ ("non-numeric bsize -- %s\n" ), optarg); + exitcode =1 ;return 0 ; } bsize = tmp;
@@ -346,6 +347,7 @@ pwrite_f( skip =cvtnum (fsblocksize, fssectsize, optarg);if (skip <0 ) {printf (_ ("non-numeric skip -- %s\n" ), optarg); + exitcode =1 ;return 0 ; }break ;
@@ -353,6 +355,7 @@ pwrite_f( seed =strtoul (optarg, &sp,0 );if (!sp || sp == optarg) {printf (_ ("non-numeric seed -- %s\n" ), optarg); + exitcode =1 ;return 0 ; }break ;
@@ -368,6 +371,7 @@ pwrite_f(if (!sp || sp == optarg) {printf (_ ("non-numeric vector count == %s\n" ), optarg); + exitcode =1 ;return 0 ; }break ;
@@ -382,11 +386,13 @@ pwrite_f( zeed =strtoul (optarg, &sp,0 );if (!sp || sp == optarg) {printf (_ ("non-numeric seed -- %s\n" ), optarg); + exitcode =1 ;return 0 ; }break ;default :/* Handle ifdef'd-out options above */ + exitcode =1 ;if (c !='?' )printf (_ ("%s: command -%c not supported\n" ), argv[0 ], c);else
@@ -394,28 +400,38 @@ pwrite_f(return 0 ; } } -if (((skip || dflag) && !infile) || (optind != argc -2 )) +if (((skip || dflag) && !infile) || (optind != argc -2 )) { + exitcode =1 ;return command_usage (&pwrite_cmd); -if (infile && direction !=IO_FORWARD ) + } +if (infile && direction !=IO_FORWARD ) { + exitcode =1 ;return command_usage (&pwrite_cmd); + } offset =cvtnum (fsblocksize, fssectsize, argv[optind]);if (offset <0 ) {printf (_ ("non-numeric offset argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; } optind++; count =cvtnum (fsblocksize, fssectsize, argv[optind]);if (count <0 ) {printf (_ ("non-numeric length argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; } -if (alloc_buffer (bsize, uflag, seed) <0 ) +if (alloc_buffer (bsize, uflag, seed) <0 ) { + exitcode =1 ;return 0 ; + } c =IO_READONLY | (dflag ?IO_DIRECT :0 ); -if (infile && ((fd =openfile (infile,NULL , c,0 ,NULL )) <0 )) +if (infile && ((fd =openfile (infile,NULL , c,0 ,NULL )) <0 )) { + exitcode =1 ;return 0 ; + }gettimeofday (&t1,NULL );switch (direction) {
@@ -438,20 +454,25 @@ pwrite_f( total =0 ;ASSERT (0 ); } -if (c <0 ) +if (c <0 ) { + exitcode =1 ; goto done; + }if (Wflag) {if (fsync (file->fd) <0 ) {perror ("fsync" ); + exitcode =1 ; goto done; } }if (wflag) {if (fdatasync (file->fd) <0 ) {perror ("fdatasync" ); + exitcode =1 ; goto done; } } +if (qflag) goto done;gettimeofday (&t2,NULL );
io/readdir.c +7 -3
@@ -163,18 +163,22 @@ readdir_f( verbose =1 ;break ;default : + exitcode =1 ;return command_usage (&readdir_cmd); } } dfd =dup (file->fd); -if (dfd <0 ) -return -1 ; +if (dfd <0 ) { + exitcode =1 ; +return 0 ; + } dir =fdopendir (dfd);if (!dir) {close (dfd); -return -1 ; + exitcode =1 ; +return 0 ; }if (offset ==-1 ) {
io/reflink.c +25 -5
@@ -75,6 +75,7 @@ dedupe_ioctl( error =ioctl (fd,XFS_IOC_FILE_EXTENT_SAME , args);if (error) {perror ("XFS_IOC_FILE_EXTENT_SAME" ); + exitcode =1 ; goto done; }if (info->status <0 ) {
@@ -129,34 +130,42 @@ dedupe_f( quiet_flag =1 ;break ;default : + exitcode =1 ;return command_usage (&dedupe_cmd); } } -if (optind != argc -4 ) +if (optind != argc -4 ) { + exitcode =1 ;return command_usage (&dedupe_cmd); + } infile = argv[optind]; optind++; soffset =cvtnum (fsblocksize, fssectsize, argv[optind]);if (soffset <0 ) {printf (_ ("non-numeric src offset argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; } optind++; doffset =cvtnum (fsblocksize, fssectsize, argv[optind]);if (doffset <0 ) {printf (_ ("non-numeric dest offset argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; } optind++; count =cvtnum (fsblocksize, fssectsize, argv[optind]);if (count <0 ) {printf (_ ("non-positive length argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; } fd =openfile (infile,NULL ,IO_READONLY ,0 ,NULL ); -if (fd <0 ) +if (fd <0 ) { + exitcode =1 ;return 0 ; + }gettimeofday (&t1,NULL ); total =dedupe_ioctl (fd, soffset, doffset, count, &ops);
@@ -250,11 +259,14 @@ reflink_f( quiet_flag =1 ;break ;default : + exitcode =1 ;return command_usage (&reflink_cmd); } } -if (optind != argc -4 && optind != argc -1 ) +if (optind != argc -4 && optind != argc -1 ) { + exitcode =1 ;return command_usage (&reflink_cmd); + } infile = argv[optind]; optind++;if (optind == argc)
@@ -262,29 +274,37 @@ reflink_f( soffset =cvtnum (fsblocksize, fssectsize, argv[optind]);if (soffset <0 ) {printf (_ ("non-numeric src offset argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; } optind++; doffset =cvtnum (fsblocksize, fssectsize, argv[optind]);if (doffset <0 ) {printf (_ ("non-numeric dest offset argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; } optind++; count =cvtnum (fsblocksize, fssectsize, argv[optind]);if (count <0 ) {printf (_ ("non-positive length argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; } clone_all: fd =openfile (infile,NULL ,IO_READONLY ,0 ,NULL ); -if (fd <0 ) +if (fd <0 ) { + exitcode =1 ;return 0 ; + }gettimeofday (&t1,NULL ); total =reflink_ioctl (fd, soffset, doffset, count, &ops); -if (ops ==0 || quiet_flag) +if (ops ==0 ) + goto done; + +if (quiet_flag) goto done;gettimeofday (&t2,NULL ); t2 =tsub (t2, t1);
io/resblks.c +3 -0
@@ -36,15 +36,18 @@ resblks_f( blks =cvtnum (file->geom.blocksize, file->geom.sectsize, argv[1 ]);if (blks <0 ) {printf (_ ("non-numeric argument -- %s\n" ), argv[1 ]); + exitcode =1 ;return 0 ; } res.resblks = blks;if (xfsctl (file->name, file->fd,XFS_IOC_SET_RESBLKS , &res) <0 ) {perror ("XFS_IOC_SET_RESBLKS" ); + exitcode =1 ;return 0 ; } }else if (xfsctl (file->name, file->fd,XFS_IOC_GET_RESBLKS , &res) <0 ) {perror ("XFS_IOC_GET_RESBLKS" ); + exitcode =1 ;return 0 ; } printf(_("reserved blocks = %llu\n"),
io/seek.c +9 -3
@@ -132,15 +132,20 @@ seek_f( startflag =1 ;break ;default : + exitcode =1 ;return command_usage (&seek_cmd); } } -if (!(flag & (SEEK_DFLAG |SEEK_HFLAG )) || optind != argc -1 ) +if (!(flag & (SEEK_DFLAG |SEEK_HFLAG )) || optind != argc -1 ) { + exitcode =1 ;return command_usage (&seek_cmd); + } start = offset =cvtnum (fsblocksize, fssectsize, argv[optind]); -if (offset <0 ) +if (offset <0 ) { + exitcode =1 ;return command_usage (&seek_cmd); + }/* * check to see if the offset is a data or hole entry and
@@ -186,9 +191,10 @@ found_hole:for (c =0 ; flag; c++) {if (offset ==-1 ) {/* print error or eof if the only entry */ -if (errno !=ENXIO || c ==0 ) +if (errno !=ENXIO || c ==0 ) {seek_output (startflag, seekinfo[current].name, start, offset); + }return 0 ;/* stop on error or EOF */ }
io/sendfile.c +15 -3
@@ -100,6 +100,7 @@ sendfile_f(if (fd <0 || fd >= filecount) {printf (_ ("value %d is out of range (0-%d)\n" ), fd, filecount-1 ); + exitcode =1 ;return 0 ; }break ;
@@ -107,22 +108,28 @@ sendfile_f( infile = optarg;break ;default : + exitcode =1 ;return command_usage (&sendfile_cmd); } } -if (infile && fd !=-1 ) +if (infile && fd !=-1 ) { + exitcode =1 ;return command_usage (&sendfile_cmd); + }if (!infile) fd = filetable[fd].fd; -else if ((fd =openfile (infile,NULL ,IO_READONLY ,0 ,NULL )) <0 ) +else if ((fd =openfile (infile,NULL ,IO_READONLY ,0 ,NULL )) <0 ) { + exitcode =1 ;return 0 ; + }if (optind == argc -2 ) { offset =cvtnum (blocksize, sectsize, argv[optind]);if (offset <0 ) {printf (_ ("non-numeric offset argument -- %s\n" ), argv[optind]); + exitcode =1 ; goto done; } optind++;
@@ -130,6 +137,7 @@ sendfile_f(if (count <0 ) {printf (_ ("non-numeric length argument -- %s\n" ), argv[optind]); + exitcode =1 ; goto done; } }else {
@@ -137,6 +145,7 @@ sendfile_f(if (fstat (fd, &stat) <0 ) {perror ("fstat" ); + exitcode =1 ; goto done; } count = stat.st_size;
@@ -144,8 +153,11 @@ sendfile_f(gettimeofday (&t1,NULL ); c =send_buffer (offset, count, fd, &total); -if (c <0 ) +if (c <0 ) { + exitcode =1 ; goto done; + } +if (qflag) goto done;gettimeofday (&t2,NULL );
io/shutdown.c +2 -0
@@ -36,12 +36,14 @@ shutdown_f( flag =XFS_FSOP_GOING_FLAGS_LOGFLUSH ;break ;default : + exitcode =1 ;return command_usage (&shutdown_cmd); } }if ((xfsctl (file->name, file->fd,XFS_IOC_GOINGDOWN , &flag)) <0 ) {perror ("XFS_IOC_GOINGDOWN" ); + exitcode =1 ;return 0 ; }return 0 ;
io/stat.c +12 -1
@@ -146,15 +146,19 @@ stat_f( verbose =1 ;break ;default : + exitcode =1 ;return command_usage (&stat_cmd); } } -if (raw && verbose) +if (raw && verbose) { + exitcode =1 ;return command_usage (&stat_cmd); + }if (fstat (file->fd, &st) <0 ) {perror ("fstat" ); + exitcode =1 ;return 0 ; }
@@ -193,6 +197,7 @@ statfs_f(printf (_ ("fd.path = \"%s\"\n" ), file->name);if (platform_fstatfs (file->fd, &st) <0 ) {perror ("fstatfs" ); + exitcode =1 ; }else {printf (_ ("statfs.f_bsize = %lld\n" ), (long long ) st.f_bsize);printf (_ ("statfs.f_blocks = %lld\n" ), (long long ) st.f_blocks);
@@ -207,6 +212,7 @@ statfs_f(return 0 ;if ((xfsctl (file->name, file->fd,XFS_IOC_FSGEOMETRY_V1 , &fsgeo)) <0 ) {perror ("XFS_IOC_FSGEOMETRY_V1" ); + exitcode =1 ; }else {printf (_ ("geom.bsize = %u\n" ), fsgeo.blocksize);printf (_ ("geom.agcount = %u\n" ), fsgeo.agcount);
@@ -223,6 +229,7 @@ statfs_f( }if ((xfsctl (file->name, file->fd,XFS_IOC_FSCOUNTS , &fscounts)) <0 ) {perror ("XFS_IOC_FSCOUNTS" ); + exitcode =1 ; }else {printf (_ ("counts.freedata = %llu\n" ), (unsigned long long ) fscounts.freedata);
@@ -327,6 +334,7 @@ statx_f(if (!p || p == optarg) {printf (_ ("non-numeric mask -- %s\n" ), optarg); + exitcode =1 ;return 0 ; } }
@@ -346,6 +354,7 @@ statx_f( atflag |=AT_STATX_DONT_SYNC ;break ;default : + exitcode =1 ;return command_usage (&statx_cmd); } }
@@ -356,8 +365,10 @@ statx_f(memset (&stx,0xbf ,sizeof (stx));if (_statx (file->fd,"" , atflag |AT_EMPTY_PATH , mask, &stx) <0 ) {perror ("statx" ); + exitcode =1 ;return 0 ; } + exitcode =0 ;if (raw)return dump_raw_statx (&stx);
io/sync_file_range.c +7 -1
@@ -58,6 +58,7 @@ sync_range_f( sync_mode =SYNC_FILE_RANGE_WRITE ;break ;default : + exitcode =1 ;return command_usage (&sync_range_cmd); } }
@@ -66,13 +67,16 @@ sync_range_f(if (!sync_mode) sync_mode =SYNC_FILE_RANGE_WRITE ; -if (optind != argc -2 ) +if (optind != argc -2 ) { + exitcode =1 ;return command_usage (&sync_range_cmd); + }init_cvtnum (&blocksize, §size); offset =cvtnum (blocksize, sectsize, argv[optind]);if (offset <0 ) {printf (_ ("non-numeric offset argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; } optind++;
@@ -80,11 +84,13 @@ sync_range_f(if (length <0 ) {printf (_ ("non-numeric length argument -- %s\n" ), argv[optind]); + exitcode =1 ;return 0 ; }if (sync_file_range (file->fd, offset, length, sync_mode) <0 ) {perror ("sync_file_range" ); + exitcode =1 ;return 0 ; }return 0 ;
io/truncate.c +2 -0
@@ -35,11 +35,13 @@ truncate_f( offset =cvtnum (blocksize, sectsize, argv[1 ]);if (offset <0 ) {printf (_ ("non-numeric truncate argument -- %s\n" ), argv[1 ]); + exitcode =1 ;return 0 ; }if (ftruncate (file->fd, offset) <0 ) {perror ("ftruncate" ); + exitcode =1 ;return 0 ; }return 0 ;
io/utimes.c +3 -0
@@ -48,17 +48,20 @@ utimes_f( result =timespec_from_string (argv[1 ], argv[2 ], &t[0 ]);if (result) {fprintf (stderr,"Bad value for atime\n" ); + exitcode =1 ;return 0 ; } result =timespec_from_string (argv[3 ], argv[4 ], &t[1 ]);if (result) {fprintf (stderr,"Bad value for mtime\n" ); + exitcode =1 ;return 0 ; }/* Call futimens to update time. */ if (futimens (file->fd, t)) {perror ("futimens" ); + exitcode =1 ;return 0 ; }
Signature · 1 line
2.17.0