mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-26 03:09:34 +03:00
Miscellaneous ZTS fixes
Coverity had various complaints about minor issues. They are all fairly straightforward to understand without reading additional files, with the exception of the draid.c issue. vdev_draid_rand() takes a 128-bit starting seed, but we were passing a pointer to a 64-bit value, which understandably made Coverity complain. This is perhaps the only significant issue fixed in this patch, since it causes stack corruption. These are not all of the issues in the ZTS that Coverity caught, but a number of them are already fixed in other PRs. There is also a class of TOUTOC complaints that involve very minor things in the ZTS (e.g. access() before unlink()). I have yet to decide whether they are false positives (since this is not security sensitive code) or something to cleanup. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Neal Gompa <ngompa@datto.com> Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu> Closes #13943
This commit is contained in:
parent
55c12724d3
commit
570ca4441e
@ -93,8 +93,8 @@ read_map(const char *filename, nvlist_t **allcfgs)
|
|||||||
rc = gzread(fp, buf + bytes, block_size);
|
rc = gzread(fp, buf + bytes, block_size);
|
||||||
if ((rc < 0) || (rc == 0 && !gzeof(fp))) {
|
if ((rc < 0) || (rc == 0 && !gzeof(fp))) {
|
||||||
free(buf);
|
free(buf);
|
||||||
(void) gzclose(fp);
|
|
||||||
(void) gzerror(fp, &error);
|
(void) gzerror(fp, &error);
|
||||||
|
(void) gzclose(fp);
|
||||||
return (error);
|
return (error);
|
||||||
} else {
|
} else {
|
||||||
bytes += rc;
|
bytes += rc;
|
||||||
@ -505,6 +505,8 @@ eval_resilver(draid_map_t *map, uint64_t groupwidth, uint64_t nspares,
|
|||||||
|
|
||||||
int *ios = calloc(map->dm_children, sizeof (uint64_t));
|
int *ios = calloc(map->dm_children, sizeof (uint64_t));
|
||||||
|
|
||||||
|
ASSERT3P(ios, !=, NULL);
|
||||||
|
|
||||||
/* Resilver all rows */
|
/* Resilver all rows */
|
||||||
for (int i = 0; i < map->dm_nperms; i++) {
|
for (int i = 0; i < map->dm_nperms; i++) {
|
||||||
uint8_t *row = &map->dm_perms[i * map->dm_children];
|
uint8_t *row = &map->dm_perms[i * map->dm_children];
|
||||||
@ -770,7 +772,7 @@ static int
|
|||||||
draid_generate(int argc, char *argv[])
|
draid_generate(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char filename[MAXPATHLEN] = {0};
|
char filename[MAXPATHLEN] = {0};
|
||||||
uint64_t map_seed;
|
uint64_t map_seed[2];
|
||||||
int c, fd, error, verbose = 0, passes = 1, continuous = 0;
|
int c, fd, error, verbose = 0, passes = 1, continuous = 0;
|
||||||
int min_children = VDEV_DRAID_MIN_CHILDREN;
|
int min_children = VDEV_DRAID_MIN_CHILDREN;
|
||||||
int max_children = VDEV_DRAID_MAX_CHILDREN;
|
int max_children = VDEV_DRAID_MAX_CHILDREN;
|
||||||
@ -847,7 +849,7 @@ restart:
|
|||||||
ssize_t bytes_read = 0;
|
ssize_t bytes_read = 0;
|
||||||
|
|
||||||
while (bytes_read < bytes) {
|
while (bytes_read < bytes) {
|
||||||
ssize_t rc = read(fd, ((char *)&map_seed) + bytes_read,
|
ssize_t rc = read(fd, ((char *)map_seed) + bytes_read,
|
||||||
bytes - bytes_read);
|
bytes - bytes_read);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
printf("Unable to read /dev/urandom: %s\n:",
|
printf("Unable to read /dev/urandom: %s\n:",
|
||||||
@ -876,7 +878,7 @@ restart:
|
|||||||
double worst_ratio = 1000.0;
|
double worst_ratio = 1000.0;
|
||||||
double avg_ratio = 1000.0;
|
double avg_ratio = 1000.0;
|
||||||
|
|
||||||
error = eval_maps(children, passes, &map_seed, &map,
|
error = eval_maps(children, passes, map_seed, &map,
|
||||||
&worst_ratio, &avg_ratio);
|
&worst_ratio, &avg_ratio);
|
||||||
if (error) {
|
if (error) {
|
||||||
printf("Error eval_maps(): %s\n", strerror(error));
|
printf("Error eval_maps(): %s\n", strerror(error));
|
||||||
|
@ -53,7 +53,7 @@ static long fsize = FSIZE;
|
|||||||
static size_t bsize = BSIZE;
|
static size_t bsize = BSIZE;
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
static int rflag = 0;
|
static int rflag = 0;
|
||||||
static int seed = 0;
|
static uint_t seed = 0;
|
||||||
static int vflag = 0;
|
static int vflag = 0;
|
||||||
static int errflag = 0;
|
static int errflag = 0;
|
||||||
static off_t offset = 0;
|
static off_t offset = 0;
|
||||||
@ -105,7 +105,7 @@ parse_options(int argc, char *argv[])
|
|||||||
extern int optind, optopt;
|
extern int optind, optopt;
|
||||||
|
|
||||||
count = fsize / bsize;
|
count = fsize / bsize;
|
||||||
seed = time(NULL);
|
seed = (uint_t)time(NULL);
|
||||||
while ((c = getopt(argc, argv, "b:c:f:o:rs:v")) != -1) {
|
while ((c = getopt(argc, argv, "b:c:f:o:rs:v")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'b':
|
case 'b':
|
||||||
|
@ -152,6 +152,11 @@ main(int argc, char *argv[])
|
|||||||
n = strtoull(argv[0], NULL, 0);
|
n = strtoull(argv[0], NULL, 0);
|
||||||
|
|
||||||
fd = open(filename, O_RDWR|O_CREAT, 0666);
|
fd = open(filename, O_RDWR|O_CREAT, 0666);
|
||||||
|
if (fd == -1) {
|
||||||
|
(void) fprintf(stderr, "open(%s) failed: %s\n", filename,
|
||||||
|
strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
err = fstat(fd, &ss);
|
err = fstat(fd, &ss);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
(void) fprintf(stderr,
|
(void) fprintf(stderr,
|
||||||
|
@ -96,7 +96,7 @@ main(int argc, char *argv[])
|
|||||||
off += bytes;
|
off += bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (diff_len != 0 && diff_len != 0) {
|
if (diff_len != 0) {
|
||||||
(void) fprintf(stdout, "%lld,%lld\n", (long long)diff_off,
|
(void) fprintf(stdout, "%lld,%lld\n", (long long)diff_off,
|
||||||
(long long)diff_len);
|
(long long)diff_len);
|
||||||
}
|
}
|
||||||
|
@ -528,7 +528,11 @@ test_recv_new(const char *dataset, int fd)
|
|||||||
ssize_t count;
|
ssize_t count;
|
||||||
|
|
||||||
int cleanup_fd = open(ZFS_DEV, O_RDWR);
|
int cleanup_fd = open(ZFS_DEV, O_RDWR);
|
||||||
|
if (cleanup_fd == -1) {
|
||||||
|
(void) fprintf(stderr, "open(%s) failed: %s\n", ZFS_DEV,
|
||||||
|
strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
(void) snprintf(snapshot, sizeof (snapshot), "%s@replicant", dataset);
|
(void) snprintf(snapshot, sizeof (snapshot), "%s@replicant", dataset);
|
||||||
|
|
||||||
count = pread(fd, &drr, sizeof (drr), 0);
|
count = pread(fd, &drr, sizeof (drr), 0);
|
||||||
|
@ -66,7 +66,7 @@ normal_writer(void *filename)
|
|||||||
err(1, "failed to open %s", file_path);
|
err(1, "failed to open %s", file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf;
|
char buf = 'z';
|
||||||
while (1) {
|
while (1) {
|
||||||
write_num = write(fd, &buf, 1);
|
write_num = write(fd, &buf, 1);
|
||||||
if (write_num == 0) {
|
if (write_num == 0) {
|
||||||
|
@ -55,7 +55,7 @@ main(int argc, char **argv)
|
|||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
char *map = NULL;
|
char *map = NULL;
|
||||||
int fd = -1, bytes, retval = 0;
|
int fd = -1, bytes, retval = 0;
|
||||||
unsigned seed;
|
uint_t seed;
|
||||||
|
|
||||||
if (argc < 2 || optind == argc) {
|
if (argc < 2 || optind == argc) {
|
||||||
(void) fprintf(stderr,
|
(void) fprintf(stderr,
|
||||||
@ -92,7 +92,7 @@ main(int argc, char **argv)
|
|||||||
retval = 1;
|
retval = 1;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
seed = time(NULL);
|
seed = (uint_t)time(NULL);
|
||||||
srandom(seed);
|
srandom(seed);
|
||||||
|
|
||||||
idx = random() % size;
|
idx = random() % size;
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -28,7 +29,19 @@ int main(void) {
|
|||||||
|
|
||||||
char buf[64];
|
char buf[64];
|
||||||
sprintf(buf, "/tmp/zts-zed_fd_spill-logdir/%d", getppid());
|
sprintf(buf, "/tmp/zts-zed_fd_spill-logdir/%d", getppid());
|
||||||
dup2(creat(buf, 0644), STDOUT_FILENO);
|
int fd = creat(buf, 0644);
|
||||||
|
if (fd == -1) {
|
||||||
|
(void) fprintf(stderr, "creat(%s) failed: %s\n", buf,
|
||||||
|
strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dup2(fd, STDOUT_FILENO) == -1) {
|
||||||
|
close(fd);
|
||||||
|
(void) fprintf(stderr, "dup2(%s, STDOUT_FILENO) failed: %s\n",
|
||||||
|
buf, strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(buf, sizeof (buf), "/proc/%d/fd", getppid());
|
snprintf(buf, sizeof (buf), "/proc/%d/fd", getppid());
|
||||||
execlp("ls", "ls", buf, NULL);
|
execlp("ls", "ls", buf, NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user