1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-09-17 21:44:24 +03:00

Compare commits

...

11 Commits

Author SHA1 Message Date
Bryn M. Reeves
d60364c634 libdm: use uint64_t where possible in filemap routines
Use uint64_t where possible and eplicit casts elsewhere to avoid
compiler warnings when converting between int, int64_t and
uint64_t.
2017-03-29 20:57:04 +01:00
Bryn M. Reeves
b5ac2c458a libdm: use size_t for buflen in _stats_group_file_regions() 2017-03-29 20:46:21 +01:00
Bryn M. Reeves
181975e635 libdm: make _stats_resize_group() num_regions argument uint64_t 2017-03-29 20:42:36 +01:00
Bryn M. Reeves
820843fcb6 libdm: make _find_extent() nr_extents argument uint64_t 2017-03-29 20:41:33 +01:00
Bryn M. Reeves
d487fcfb0e dmfilemapd: cast return value of strto* functions when needed 2017-03-29 20:32:55 +01:00
Bryn M. Reeves
f1e42e2186 dmfilemapd: use log_sys_error in _filemap_monitor_set_notify
Since _filemap_monitor_set_notify() is only called after daemon
start up it should not use the _early_log() macros. Use
log_sys_error to log errors from the two syscalls in the function.
2017-03-29 20:29:20 +01:00
Bryn M. Reeves
3c69a7248a dmfilemapd: cast sysconf() return value to int 2017-03-29 20:28:43 +01:00
Bryn M. Reeves
00e716b037 dmfilemapd: fix len type in _filemap_monitor_check_file_unlinked()
Make 'len' a size_t to match the return type of readlink(2).
2017-03-29 20:26:39 +01:00
Bryn M. Reeves
926ce7e279 dmfilemapd: make filemap_monitor->nr_regions uint64_t 2017-03-29 20:23:57 +01:00
Bryn M. Reeves
6582cc4ff2 libdm: use DM_STATS_GROUP_* constants in dm_stats_create_regions_from_fd 2017-03-29 20:02:26 +01:00
Bryn M. Reeves
618f9ab04b dmsetup: simplify branching in _stats_update_file()
The fallback branch in _stats_update_file() is redundant (since the
branch taken when the daemon starts successfully must jump to the
'out' label anyway): remove it and re-order the conditions to
improve readability.
2017-03-29 18:35:27 +01:00
3 changed files with 41 additions and 34 deletions

View File

@@ -55,7 +55,7 @@ struct filemap_monitor {
/* monitoring heuristics */
int64_t blocks; /* allocated blocks, from stat.st_blocks */
int64_t nr_regions;
uint64_t nr_regions;
int deleted;
};
@@ -225,7 +225,7 @@ static int _is_open(const char *path)
while ((proc_dp = readdir(proc_d)) != NULL) {
if (!isdigit(proc_dp->d_name[0]))
continue;
pid = strtol(proc_dp->d_name, NULL, 10);
pid = (pid_t) strtol(proc_dp->d_name, NULL, 10);
if (!pid)
continue;
if (_is_open_in_pid(pid, path)) {
@@ -280,7 +280,7 @@ static int _parse_args(int argc, char **argv, struct filemap_monitor *fm)
fm->nr_regions = 1;
/* parse <fd> */
fm->fd = strtol(argv[0], &endptr, 10);
fm->fd = (int) strtol(argv[0], &endptr, 10);
if (*endptr) {
_early_log("Could not parse file descriptor: %s", argv[0]);
return 0;
@@ -334,7 +334,7 @@ static int _parse_args(int argc, char **argv, struct filemap_monitor *fm)
/* parse [<foreground>[<verbose>]] */
if (argc) {
_foreground = strtol(argv[0], &endptr, 10);
_foreground = (int) strtol(argv[0], &endptr, 10);
if (*endptr) {
_early_log("Could not parse debug argument: %s.",
argv[0]);
@@ -343,7 +343,7 @@ static int _parse_args(int argc, char **argv, struct filemap_monitor *fm)
argc--;
argv++;
if (argc) {
_verbose = strtol(argv[0], &endptr, 10);
_verbose = (int) strtol(argv[0], &endptr, 10);
if (*endptr) {
_early_log("Could not parse verbose "
"argument: %s", argv[0]);
@@ -409,13 +409,13 @@ static int _filemap_monitor_set_notify(struct filemap_monitor *fm)
* and does not fork or exec.
*/
if ((inotify_fd = inotify_init1(IN_NONBLOCK)) < 0) {
_early_log("Failed to initialise inotify.");
log_sys_error("inotify_init1", "IN_NONBLOCK");
return 0;
}
if ((watch_fd = inotify_add_watch(inotify_fd, fm->path,
IN_MODIFY | IN_DELETE_SELF)) < 0) {
_early_log("Failed to add inotify watch.");
log_sys_error("inotify_add_watch", fm->path);
return 0;
}
fm->inotify_fd = inotify_fd;
@@ -559,7 +559,8 @@ static int _filemap_monitor_check_file_unlinked(struct filemap_monitor *fm)
{
char path_buf[PATH_MAX];
char link_buf[PATH_MAX];
int same, fd, len;
int same, fd;
ssize_t len;
fm->deleted = 0;
@@ -659,7 +660,7 @@ static int _daemonise(struct filemap_monitor *fm)
}
}
for (fd = sysconf(_SC_OPEN_MAX) - 1; fd > STDERR_FILENO; fd--) {
for (fd = (int) sysconf(_SC_OPEN_MAX) - 1; fd > STDERR_FILENO; fd--) {
if (fd == fm->fd)
continue;
close(fd);

View File

@@ -4181,21 +4181,23 @@ int dm_stats_get_group_descriptor(const struct dm_stats *dms,
* Resize the group bitmap corresponding to group_id so that it can
* contain at least num_regions members.
*/
static int _stats_resize_group(struct dm_stats_group *group, int num_regions)
static int _stats_resize_group(struct dm_stats_group *group,
uint64_t num_regions)
{
int last_bit = dm_bit_get_last(group->regions);
uint64_t last_bit = dm_bit_get_last(group->regions);
dm_bitset_t new, old;
if (last_bit >= num_regions) {
log_error("Cannot resize group bitmap to %d with bit %d set.",
num_regions, last_bit);
log_error("Cannot resize group bitmap to " FMTu64
" with bit " FMTu64 " set.", num_regions, last_bit);
return 0;
}
log_very_verbose("Resizing group bitmap from %d to %d (last_bit: %d).",
log_very_verbose("Resizing group bitmap from " FMTu64
" to " FMTu64 " (last_bit: " FMTu64 ").",
group->regions[0], num_regions, last_bit);
new = dm_bitset_create(NULL, num_regions);
new = dm_bitset_create(NULL, (unsigned) num_regions);
if (!new) {
log_error("Could not allocate memory for new group bitmap.");
return 0;
@@ -4217,7 +4219,7 @@ static int _stats_group_file_regions(struct dm_stats *dms, uint64_t *region_ids,
dm_bitset_t regions = dm_bitset_create(NULL, dms->nr_regions);
uint64_t i, group_id = DM_STATS_GROUP_NOT_PRESENT;
char *members = NULL;
int buflen;
size_t buflen;
if (!regions) {
log_error("Cannot map file: failed to allocate group bitmap.");
@@ -4472,7 +4474,7 @@ bad:
#define MATCH_EXTENT(e, s, l) \
(((e).start == (s)) && ((e).len == (l)))
static struct _extent *_find_extent(size_t nr_extents, struct _extent *extents,
static struct _extent *_find_extent(uint64_t nr_extents, struct _extent *extents,
uint64_t start, uint64_t len)
{
size_t i;
@@ -4509,8 +4511,9 @@ static int _stats_unmap_regions(struct dm_stats *dms, uint64_t group_id,
{
struct dm_stats_region *region = NULL;
struct dm_stats_group *group = NULL;
int64_t nr_kept, nr_old, i;
uint64_t nr_kept, nr_old;
struct _extent ext;
int64_t i;
group = &dms->groups[group_id];
@@ -4569,7 +4572,7 @@ static int _stats_unmap_regions(struct dm_stats *dms, uint64_t group_id,
log_very_verbose("Found " FMTu64 " new extents",
*count - nr_kept);
return nr_kept;
return (int) nr_kept;
out:
dm_pool_abandon_object(mem);
return -1;
@@ -4592,15 +4595,15 @@ static uint64_t *_stats_map_file_regions(struct dm_stats *dms, int fd,
uint64_t *count, int *regroup)
{
struct _extent *extents = NULL, *old_extents = NULL;
uint64_t *regions = NULL, fail_region;
uint64_t *regions = NULL, fail_region, i, num_bits;
struct dm_stats_group *group = NULL;
struct dm_pool *extent_mem = NULL;
struct _extent *old_ext;
char *hist_arg = NULL;
int update, num_bits;
struct statfs fsbuf;
int64_t nr_kept = 0, i;
int64_t nr_kept = 0;
struct stat buf;
int update;
update = _stats_group_id_present(dms, group_id);
@@ -4685,9 +4688,10 @@ static uint64_t *_stats_map_file_regions(struct dm_stats *dms, int fd,
*/
for (i = 0; i < *count; i++) {
if (update) {
if ((old_ext = _find_extent(nr_kept, old_extents,
extents[i].start,
extents[i].len))) {
if ((old_ext = _find_extent((uint64_t) nr_kept,
old_extents,
extents[i].start,
extents[i].len))) {
regions[i] = old_ext->id;
continue;
}
@@ -4777,7 +4781,8 @@ uint64_t *dm_stats_create_regions_from_fd(struct dm_stats *dms, int fd,
}
if (!(regions = _stats_map_file_regions(dms, fd, bounds, precise,
-1, &count, &regroup)))
DM_STATS_GROUP_NOT_PRESENT,
&count, &regroup)))
return NULL;
if (!group)

View File

@@ -5716,17 +5716,18 @@ static int _stats_update_file(CMD_ARGS)
* If starting the daemon fails, fall back to a direct update.
*/
if (!_switches[NOMONITOR_ARG]) {
if (!dm_stats_start_filemapd(fd, group_id, abspath, mode,
foreground, verbose)) {
log_warn("Failed to start filemap monitoring daemon.");
goto fallback;
}
goto out;
if (dm_stats_start_filemapd(fd, group_id, abspath, mode,
foreground, verbose))
goto out;
log_warn("Failed to start filemap monitoring daemon.");
/* fall back to one-shot update */
}
fallback:
/*
* --nomonitor case - perform a one-shot update directly from dmstats.
* --nomonitor and fall back case - perform a one-shot update directly
* from dmsetup.
*/
regions = dm_stats_update_regions_from_fd(dms, fd, group_id);