main - cov: use different variable name
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=825e49a2447810a8069...
Commit: 825e49a2447810a806905723bc91072eb7b8b423
Parent: 376e7072323bc394341c7b9a43a7ca51c2b9e400
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Sep 19 20:25:58 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:26:09 2021 +0200
cov: use different variable name
Better for Coverity to see no change for possibly opened handle.
---
libdaemon/server/daemon-server.c | 12 ++++++------
libdm/dm-tools/dmfilemapd.c | 8 ++++----
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c
index 1e900261c..aeb1870a3 100644
--- a/libdaemon/server/daemon-server.c
+++ b/libdaemon/server/daemon-server.c
@@ -326,7 +326,7 @@ static void _remove_lockfile(const char *file)
static void _daemonise(daemon_state s)
{
int child_status;
- int fd;
+ int fd, ffd;
pid_t pid;
struct rlimit rlim;
struct timeval tval;
@@ -394,17 +394,17 @@ static void _daemonise(daemon_state s)
/* Switch to sysconf(_SC_OPEN_MAX) ?? */
if (getrlimit(RLIMIT_NOFILE, &rlim) < 0)
- fd = 256; /* just have to guess */
+ ffd = 256; /* just have to guess */
else
- fd = rlim.rlim_cur;
+ ffd = rlim.rlim_cur;
- for (--fd; fd > STDERR_FILENO; fd--) {
+ for (--ffd; ffd > STDERR_FILENO; ffd--) {
#ifdef __linux__
/* Do not close fds preloaded by systemd! */
- if (_systemd_activation && fd == SD_FD_SOCKET_SERVER)
+ if (_systemd_activation && ffd == SD_FD_SOCKET_SERVER)
continue;
#endif
- (void) close(fd);
+ (void) close(ffd);
}
setsid();
diff --git a/libdm/dm-tools/dmfilemapd.c b/libdm/dm-tools/dmfilemapd.c
index 2a86810ed..3799efd83 100644
--- a/libdm/dm-tools/dmfilemapd.c
+++ b/libdm/dm-tools/dmfilemapd.c
@@ -629,7 +629,7 @@ check_unlinked:
static int _daemonise(struct filemap_monitor *fm)
{
pid_t pid = 0;
- int fd;
+ int fd, ffd;
if (!setsid()) {
_early_log("setsid failed.");
@@ -670,10 +670,10 @@ static int _daemonise(struct filemap_monitor *fm)
(void) close(fd);
}
/* TODO: Use libdaemon/server/daemon-server.c _daemonise() */
- for (fd = (int) sysconf(_SC_OPEN_MAX) - 1; fd > STDERR_FILENO; fd--) {
- if (fd == fm->fd)
+ for (ffd = (int) sysconf(_SC_OPEN_MAX) - 1; ffd > STDERR_FILENO; --ffd) {
+ if (ffd == fm->fd)
continue;
- (void) close(fd);
+ (void) close(ffd);
}
return 1;
2 years, 7 months
main - cov: better handle reallocation of adapt_file
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=376e7072323bc394341...
Commit: 376e7072323bc394341c7b9a43a7ca51c2b9e400
Parent: ce907bcd26f4814966a814771f9c1d01c80c9b01
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Sep 19 20:24:35 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:26:09 2021 +0200
cov: better handle reallocation of adapt_file
If the option would be given more then once.
---
daemons/lvmlockd/lvmlockd-core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c
index 35c9b6c25..701372220 100644
--- a/daemons/lvmlockd/lvmlockd-core.c
+++ b/daemons/lvmlockd/lvmlockd-core.c
@@ -6305,6 +6305,7 @@ int main(int argc, char *argv[])
case '0':
break;
case 128:
+ free((void *) adopt_file);
adopt_file = strdup(optarg);
break;
case 'h':
2 years, 7 months
main - cov: handle teoretical sysconf failure
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ce907bcd26f4814966a...
Commit: ce907bcd26f4814966a814771f9c1d01c80c9b01
Parent: f410035181d8c524ffc5d0f3edf512e8506b47d9
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Sep 19 20:23:24 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:26:09 2021 +0200
cov: handle teoretical sysconf failure
sysconf() may also return -1 although rather theoretically.
Default to 4K when such case would happen.
Also in function call it just once and keep as static variable.
---
lib/device/bcache.c | 20 +++++++++++++-------
test/unit/bcache_t.c | 2 +-
test/unit/bcache_utils_t.c | 2 +-
test/unit/framework.h | 2 ++
test/unit/io_engine_t.c | 3 +--
5 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/lib/device/bcache.c b/lib/device/bcache.c
index 285d92bc7..be25cc7e2 100644
--- a/lib/device/bcache.c
+++ b/lib/device/bcache.c
@@ -358,10 +358,16 @@ static unsigned _async_max_io(struct io_engine *e)
struct io_engine *create_async_io_engine(void)
{
+ static int _pagesize = 0;
int r;
- struct async_engine *e = malloc(sizeof(*e));
+ struct async_engine *e;
- if (!e)
+ if ((_pagesize <= 0) && (_pagesize = sysconf(_SC_PAGESIZE)) < 0) {
+ log_warn("_SC_PAGESIZE returns negative value.");
+ return NULL;
+ }
+
+ if (!(e = malloc(sizeof(*e))))
return NULL;
e->e.destroy = _async_destroy;
@@ -384,7 +390,7 @@ struct io_engine *create_async_io_engine(void)
return NULL;
}
- e->page_mask = sysconf(_SC_PAGESIZE) - 1;
+ e->page_mask = (unsigned) _pagesize - 1;
return &e->e;
}
@@ -1087,12 +1093,12 @@ static void _preemptive_writeback(struct bcache *cache)
struct bcache *bcache_create(sector_t block_sectors, unsigned nr_cache_blocks,
struct io_engine *engine)
{
+ static long _pagesize = 0;
struct bcache *cache;
unsigned max_io = engine->max_io(engine);
- long pgsize = sysconf(_SC_PAGESIZE);
int i;
- if (pgsize < 0) {
+ if ((_pagesize <= 0) && ((_pagesize = sysconf(_SC_PAGESIZE)) < 0)) {
log_warn("WARNING: _SC_PAGESIZE returns negative value.");
return NULL;
}
@@ -1107,7 +1113,7 @@ struct bcache *bcache_create(sector_t block_sectors, unsigned nr_cache_blocks,
return NULL;
}
- if (block_sectors & ((pgsize >> SECTOR_SHIFT) - 1)) {
+ if (block_sectors & ((_pagesize >> SECTOR_SHIFT) - 1)) {
log_warn("bcache block size must be a multiple of page size");
return NULL;
}
@@ -1144,7 +1150,7 @@ struct bcache *bcache_create(sector_t block_sectors, unsigned nr_cache_blocks,
cache->write_misses = 0;
cache->prefetches = 0;
- if (!_init_free_list(cache, nr_cache_blocks, pgsize)) {
+ if (!_init_free_list(cache, nr_cache_blocks, _pagesize)) {
cache->engine->destroy(cache->engine);
radix_tree_destroy(cache->rtree);
free(cache);
diff --git a/test/unit/bcache_t.c b/test/unit/bcache_t.c
index 878ed5996..3231b76e0 100644
--- a/test/unit/bcache_t.c
+++ b/test/unit/bcache_t.c
@@ -380,7 +380,7 @@ static void _large_fixture_exit(void *context)
*--------------------------------------------------------------*/
#define MEG 2048
#define SECTOR_SHIFT 9
-#define PAGE_SIZE_SECTORS (sysconf(_SC_PAGE_SIZE) >> SECTOR_SHIFT)
+#define PAGE_SIZE_SECTORS ((PAGE_SIZE) >> SECTOR_SHIFT)
static void good_create(sector_t block_size, unsigned nr_cache_blocks)
{
diff --git a/test/unit/bcache_utils_t.c b/test/unit/bcache_utils_t.c
index 517a46e1d..573fc1533 100644
--- a/test/unit/bcache_utils_t.c
+++ b/test/unit/bcache_utils_t.c
@@ -26,7 +26,7 @@
//----------------------------------------------------------------
-#define T_BLOCK_SIZE sysconf(_SC_PAGESIZE)
+#define T_BLOCK_SIZE (PAGE_SIZE)
#define NR_BLOCKS 64
#define INIT_PATTERN 123
diff --git a/test/unit/framework.h b/test/unit/framework.h
index 0c455969c..f7f5b5bb9 100644
--- a/test/unit/framework.h
+++ b/test/unit/framework.h
@@ -44,6 +44,8 @@ void test_fail(const char *fmt, ...)
extern jmp_buf test_k;
#define TEST_FAILED 1
+#define PAGE_SIZE ({ int ps = sysconf(_SC_PAGESIZE); (ps > 0) ? ps : 4096 ; })
+
//-----------------------------------------------------------------
#endif
diff --git a/test/unit/io_engine_t.c b/test/unit/io_engine_t.c
index c864fa338..89fa4b787 100644
--- a/test/unit/io_engine_t.c
+++ b/test/unit/io_engine_t.c
@@ -28,8 +28,7 @@
#define SECTOR_SHIFT 9
#define SECTOR_SIZE 512
#define BLOCK_SIZE_SECTORS 8
-#define PAGE_SIZE sysconf(_SC_PAGESIZE)
-#define PAGE_SIZE_SECTORS (PAGE_SIZE >> SECTOR_SHIFT)
+#define PAGE_SIZE_SECTORS ((PAGE_SIZE) >> SECTOR_SHIFT)
#define NR_BLOCKS 64
struct fixture {
2 years, 7 months
main - cov: check fid instance is created
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=f410035181d8c524ffc...
Commit: f410035181d8c524ffc5d0f3edf512e8506b47d9
Parent: e1840dd9e0b3be55281466e60a9a07cce068db4f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 20 02:09:16 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:26:09 2021 +0200
cov: check fid instance is created
---
tools/pvscan.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/tools/pvscan.c b/tools/pvscan.c
index d24ee5724..ec33c9a9a 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -1234,7 +1234,12 @@ static int _online_devs(struct cmd_context *cmd, int do_all, struct dm_list *pvs
}
fmt = lvmcache_fmt(info);
- fid = fmt->ops->create_instance(fmt, &fic);
+ if (!(fid = fmt->ops->create_instance(fmt, &fic))) {
+ log_error("pvscan[%d] failed to create format instance.", getpid());
+ ret = 0;
+ continue;
+ }
+
vg = NULL;
mda1 = lvmcache_get_dev_mda(dev, 1);
2 years, 7 months
main - cov: add error path for daemon_request_extend
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e1840dd9e0b3be55281...
Commit: e1840dd9e0b3be55281466e60a9a07cce068db4f
Parent: 6427803252354203dfa5d816c6a8dc0ae385051e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 20 01:48:30 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:26:09 2021 +0200
cov: add error path for daemon_request_extend
Check for errors in daemon_request_extend().
---
lib/locking/lvmlockd.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/lib/locking/lvmlockd.c b/lib/locking/lvmlockd.c
index 2284d60fe..4f9952d5b 100644
--- a/lib/locking/lvmlockd.c
+++ b/lib/locking/lvmlockd.c
@@ -186,7 +186,7 @@ static int _lockd_result(daemon_reply reply, int *result, uint32_t *lockd_flags)
static daemon_reply _lockd_send_with_pvs(const char *req_name,
const struct lvmlockd_pvs *lock_pvs, ...)
{
- daemon_reply repl;
+ daemon_reply repl = { .error = -1 };
daemon_request req;
int i;
char key[32];
@@ -201,18 +201,23 @@ static daemon_reply _lockd_send_with_pvs(const char *req_name,
/* Pass PV list */
if (lock_pvs && lock_pvs->num) {
- daemon_request_extend(req, "path_num = " FMTd64,
- (int64_t)(lock_pvs)->num, NULL);
-
+ if (!daemon_request_extend(req, "path_num = " FMTd64,
+ (int64_t)(lock_pvs)->num, NULL)) {
+ log_error("Failed to create pvs request.");
+ goto bad;
+ }
for (i = 0; i < lock_pvs->num; i++) {
snprintf(key, sizeof(key), "path[%d] = %%s", i);
val = lock_pvs->path[i] ? lock_pvs->path[i] : "none";
- daemon_request_extend(req, key, val, NULL);
+ if (!daemon_request_extend(req, key, val, NULL)) {
+ log_error("Failed to create pvs request.");
+ goto bad;
+ }
}
}
repl = daemon_send(_lvmlockd, req);
-
+bad:
daemon_request_destroy(req);
return repl;
2 years, 7 months
main - cov: pvck validates setup_device return value
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=6427803252354203dfa...
Commit: 6427803252354203dfa5d816c6a8dc0ae385051e
Parent: b6e9892bc6ae23406847a20236c7c954792468e5
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 20 10:33:33 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:18:13 2021 +0200
cov: pvck validates setup_device return value
---
tools/pvck.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/tools/pvck.c b/tools/pvck.c
index 49bcb5fd3..629e1feee 100644
--- a/tools/pvck.c
+++ b/tools/pvck.c
@@ -3178,9 +3178,10 @@ int pvck(struct cmd_context *cmd, int argc, char **argv)
* but this is here to preserve the historical output.
*/
- if (argc == 1)
- setup_device(cmd, argv[0]);
- else if (!setup_devices(cmd))
+ if (argc == 1) {
+ if (!setup_device(cmd, argv[0]))
+ return_ECMD_FAILED;
+ } else if (!setup_devices(cmd))
return_ECMD_FAILED;
for (i = 0; i < argc; i++) {
2 years, 7 months
main - tests: use single funtion to get random value
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b6e9892bc6ae2340684...
Commit: b6e9892bc6ae23406847a20236c7c954792468e5
Parent: a428856a212fc9f24374de84b7f3b781502c8cf6
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 20 10:32:32 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:18:13 2021 +0200
tests: use single funtion to get random value
---
test/unit/bcache_utils_t.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/unit/bcache_utils_t.c b/test/unit/bcache_utils_t.c
index 3dea17ac5..517a46e1d 100644
--- a/test/unit/bcache_utils_t.c
+++ b/test/unit/bcache_utils_t.c
@@ -339,7 +339,7 @@ static void _test_zero_many_boundaries(void *fixture)
static void _set_cycle(struct fixture *f, uint64_t b, uint64_t e)
{
- uint8_t val = random();
+ uint8_t val = _random_pattern();
_verify(f, b, e, INIT_PATTERN);
_do_set(f, b, e, val);
2 years, 7 months
main - tests: fix test of read buffer
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a428856a212fc9f2437...
Commit: a428856a212fc9f24374de84b7f3b781502c8cf6
Parent: becffe4567543e3e0c51c728a4b266cf94fd2cdf
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Sep 19 20:17:22 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:18:13 2021 +0200
tests: fix test of read buffer
Patch 7aba7fe68b6da2ca8ec7b01f5730396d64426fb0 incorrectly
converted SECTOR_SIZE * BLOCK_SIZE_SECTORS to sizeof(f->data).
---
test/unit/io_engine_t.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/unit/io_engine_t.c b/test/unit/io_engine_t.c
index a1b219530..c864fa338 100644
--- a/test/unit/io_engine_t.c
+++ b/test/unit/io_engine_t.c
@@ -154,7 +154,7 @@ static void _test_read(void *fixture)
T_ASSERT(io.completed);
T_ASSERT(!io.error);
- _check_buffer(f->data, 123, sizeof(f->data));
+ _check_buffer(f->data, 123, SECTOR_SIZE * BLOCK_SIZE_SECTORS);
}
static void _test_write(void *fixture)
2 years, 7 months
main - gcc-fanalyzer: drop zeroing of pointers
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=becffe4567543e3e0c5...
Commit: becffe4567543e3e0c51c728a4b266cf94fd2cdf
Parent: 909401226cd7219fa07389bc396723b0c01cd9dd
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 20 13:53:20 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:18:13 2021 +0200
gcc-fanalyzer: drop zeroing of pointers
This explicit pointer zeroing is not needed since
we use 'zalloced' buffers.
---
lib/format_text/archiver.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/lib/format_text/archiver.c b/lib/format_text/archiver.c
index fae368784..87e4edc40 100644
--- a/lib/format_text/archiver.c
+++ b/lib/format_text/archiver.c
@@ -50,8 +50,6 @@ int archive_init(struct cmd_context *cmd, const char *dir,
return 0;
}
- cmd->archive_params->dir = NULL;
-
if (!*dir)
return 1;
@@ -195,7 +193,6 @@ int backup_init(struct cmd_context *cmd, const char *dir,
return 0;
}
- cmd->backup_params->dir = NULL;
if (!*dir)
return 1;
2 years, 7 months
main - gcc-fanalyzer: rewrite _fetch_string
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=909401226cd7219fa07...
Commit: 909401226cd7219fa07389bc396723b0c01cd9dd
Parent: 30b188857c51144cd4103850f93287004cc5acaa
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 20 13:51:20 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:18:13 2021 +0200
gcc-fanalyzer: rewrite _fetch_string
Slightly more optimal code, that is less confusing analyzers.
---
daemons/dmeventd/libdevmapper-event.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/daemons/dmeventd/libdevmapper-event.c b/daemons/dmeventd/libdevmapper-event.c
index 7e09ff07b..237be9fec 100644
--- a/daemons/dmeventd/libdevmapper-event.c
+++ b/daemons/dmeventd/libdevmapper-event.c
@@ -709,15 +709,11 @@ int dm_event_unregister_handler(const struct dm_event_handler *dmevh)
static char *_fetch_string(char **src, const int delimiter)
{
char *p, *ret;
+ size_t len = (p = strchr(*src, delimiter)) ?
+ p - *src : strlen(*src);
- if ((p = strchr(*src, delimiter)))
- *p = 0;
-
- if ((ret = strdup(*src)))
- *src += strlen(ret) + 1;
-
- if (p)
- *p = delimiter;
+ if ((ret = strndup(*src, len)))
+ *src += len + 1;
return ret;
}
2 years, 7 months