mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-18 02:20:59 +03:00
2a493a4c71
Coverity complained about unchecked return values and unused values that turned out to be unused return values. Different approaches were used to handle the different cases of unchecked return values: * cmd/zdb/zdb.c: VERIFY0 was used in one place since the existing code had no error handling. An error message was printed in another to match the rest of the code. * cmd/zed/agents/zfs_retire.c: We dismiss the return value with `(void)` because the value is expected to be potentially unset. * cmd/zpool_influxdb/zpool_influxdb.c: We dismiss the return value with `(void)` because the values are expected to be potentially unset. * cmd/ztest.c: VERIFY0 was used since we want failures if something goes wrong in ztest. * module/zfs/dsl_dir.c: We dismiss the return value with `(void)` because there is no guarantee that the zap entry will always be there. For example, old pools imported readonly would not have it and we do not want to fail here because of that. * module/zfs/zfs_fm.c: `fnvlist_add_*()` was used since the allocations sleep and thus can never fail. * module/zfs/zvol.c: We dismiss the return value with `(void)` because we do not need it. This matches what is already done in the analogous `zfs_replay_write2()`. * tests/zfs-tests/cmd/draid.c: We suppress one return value with `(void)` since the code handles errors already. The other return value is handled by switching to `fnvlist_lookup_uint8_array()`. * tests/zfs-tests/cmd/file/file_fadvise.c: We add error handling. * tests/zfs-tests/cmd/mmap_sync.c: We add error handling for munmap, but ignore failures on remove() with (void) since it is expected to be able to fail. * tests/zfs-tests/cmd/mmapwrite.c: We add error handling. As for unused return values, they were all in places where there was error handling, so logic was added to handle the return values. Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu> Closes #13920
102 lines
2.1 KiB
C
102 lines
2.1 KiB
C
/*
|
|
* CDDL HEADER START
|
|
*
|
|
* The contents of this file are subject to the terms of the
|
|
* Common Development and Distribution License (the "License").
|
|
* You may not use this file except in compliance with the License.
|
|
*
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
* or https://opensource.org/licenses/CDDL-1.0.
|
|
* See the License for the specific language governing permissions
|
|
* and limitations under the License.
|
|
*
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
*
|
|
* CDDL HEADER END
|
|
*/
|
|
|
|
/*
|
|
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
|
|
* Use is subject to license terms.
|
|
*/
|
|
|
|
/*
|
|
* Copyright (c) 2022 by Information2 Software, Inc. All rights reserved.
|
|
*/
|
|
|
|
#include "file_common.h"
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
|
|
/*
|
|
* Call fadvise to prefetch data
|
|
*/
|
|
static const char *execname = "file_fadvise";
|
|
|
|
static void
|
|
usage(void)
|
|
{
|
|
(void) fprintf(stderr,
|
|
"usage: %s -f filename -a advise \n", execname);
|
|
}
|
|
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
char *filename = NULL;
|
|
int advise = 0;
|
|
int fd, ch;
|
|
int err = 0;
|
|
|
|
while ((ch = getopt(argc, argv, "a:f:")) != EOF) {
|
|
switch (ch) {
|
|
case 'a':
|
|
advise = atoll(optarg);
|
|
break;
|
|
case 'f':
|
|
filename = optarg;
|
|
break;
|
|
case '?':
|
|
(void) printf("unknown arg %c\n", optopt);
|
|
usage();
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!filename) {
|
|
(void) printf("Filename not specified (-f <file>)\n");
|
|
err++;
|
|
}
|
|
|
|
if (advise < POSIX_FADV_NORMAL || advise > POSIX_FADV_NOREUSE) {
|
|
(void) printf("advise is invalid\n");
|
|
err++;
|
|
}
|
|
|
|
if (err) {
|
|
usage(); /* no return */
|
|
return (1);
|
|
}
|
|
|
|
if ((fd = open(filename, O_RDWR, 0666)) < 0) {
|
|
perror("open");
|
|
return (1);
|
|
}
|
|
|
|
if (posix_fadvise(fd, 0, 0, advise) != 0) {
|
|
perror("posix_fadvise");
|
|
close(fd);
|
|
return (1);
|
|
}
|
|
|
|
close(fd);
|
|
|
|
return (0);
|
|
}
|