Static analyzis set
cover Static analyzis set
This is mostly the last bigger patch sets for covering issues reported by Coverity tool.
Few patches needs some closer looking,
Most of them are trivial, but as they may present some forgotten tests or missing code I'm posting them for review.
Zdenek Kabelac (23):
Remove dead assignment to thisfd
Remove dead assignment
Remove dead assigment of mirr_state
Remove dead assignment of lock_flags
Remove dead assignment in vgconvert_single
Log of pthread_join operation
Move lastfd handling into for()
Fix memory leak in error path of restart_clvmd Add test for errors in _setup_task
Fix memory leak of dev_filter on error path
Add stack traces for archive
Add tests for dm_task_set operations
Make it obvious this code is not used
Add stack trace for backup and backup_remove Add test check for find_config_str
Remove check for vg != NULL
Add check for dm_snprintf result
Return PERCENT_INVALID for error case
Warning - dead code problem elimination
exit if lvmchache_init fails
Add default error path for get_property
Remove dead assignment in dm_event_get_registered_device Remove dead assignment in vg_split_mdas
daemons/clvmd/clvmd-command.c | 3 +- daemons/clvmd/clvmd.c | 25 ++++++++++--------- daemons/dmeventd/dmeventd.c | 3 +- daemons/dmeventd/libdevmapper-event.c | 41 +++++++++++++++++--------------- lib/activate/dev_manager.c | 21 ++++++++++------ lib/commands/toolcontext.c | 2 + lib/filters/filter-persistent.c | 22 ++++++++++++----- lib/format_text/archiver.c | 9 +++++-- lib/format_text/import_vsn1.c | 18 ++++++-------- lib/locking/cluster_locking.c | 14 ++++++----- lib/locking/file_locking.c | 16 +++++++++--- lib/metadata/metadata.c | 8 +++--- lib/mirror/mirrored.c | 3 -- lib/report/properties.c | 15 +++++++----- liblvm/lvm_misc.c | 4 +++ tools/lvscan.c | 6 ----- tools/polldaemon.c | 3 +- tools/vgconvert.c | 4 +-- tools/vgrename.c | 6 +++- 19 files changed, 125 insertions(+), 98 deletions(-)
--
1.7.3.4
PATCH 1/23 Remove dead assignment to thisfd
Value 'thisfd' is not read again after this assigment.
--- daemons/clvmd/clvmd.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
daemons/clvmd/clvmd.c +0 -2
@@ -827,7 +827,6 @@ static void main_loop(int local_sock, int cmd_timeout)struct local_client *free_fd; lastfd->next = thisfd->next; free_fd = thisfd; - thisfd = lastfd;DEBUGLOG ("removeme set for fd %d\n" , free_fd->fd);
@@ -863,7 +862,6 @@ static void main_loop(int local_sock, int cmd_timeout) ret, errno); lastfd->next = thisfd->next; free_fd = thisfd; - thisfd = lastfd;safe_close (&(free_fd->fd));/* Queue cleanup, this also frees the client struct */
Signature · 1 line
1.7.3.4
PATCH 2/23 Remove dead assignment
In reply to Zdenek KabelacVariables 'lv_total' and 'lv_capasity_total' are unused.
--- tools/lvscan.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)
tools/lvscan.c +0 -6
@@ -19,8 +19,6 @@ static int lvscan_single(struct cmd_context *cmd, struct logical_volume *lv, void *handle __attribute__((unused))) {struct lvinfo info; -int lv_total =0 ; -uint64_t lv_capacity_total =0 ;int inkernel, snap_active =1 ;struct lv_segment *snap_seg =NULL ;percent_t snap_percent;/* fused, fsize; */
@@ -66,10 +64,6 @@ static int lvscan_single(struct cmd_context *cmd, struct logical_volume *lv,display_size (cmd, lv->size), get_alloc_string(lv->alloc)); - lv_total++; - - lv_capacity_total += lv->size; -return ECMD_PROCESSED ; }
Signature · 1 line
1.7.3.4
PATCH 3/23 Remove dead assigment of mirr_state
In reply to Zdenek KabelacVariable 'mirr_state' is not used.
--- lib/mirror/mirrored.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
lib/mirror/mirrored.c +0 -3
@@ -184,7 +184,6 @@ static int _mirrored_target_percent(void **target_state,uint64_t *total_numerator, uint64_t *total_denominator) { - struct mirror_state *mirr_state; uint64_t numerator, denominator;unsigned mirror_count, m;int used;
@@ -193,8 +192,6 @@ static int _mirrored_target_percent(void **target_state,if (!*target_state) *target_state =_mirrored_init_target (mem, cmd); - mirr_state = *target_state; -/* Status line: <#mirrors> (maj:min)+ <synced>/<total_regions> */ log_debug ("Mirror status: %s" , params);
Signature · 1 line
1.7.3.4
PATCH 4/23 Remove dead assignment of lock_flags
In reply to Zdenek KabelacVariable 'lock_flags' is not used.
--- daemons/clvmd/clvmd-command.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
daemons/clvmd/clvmd-command.c +0 -2
@@ -182,7 +182,6 @@ static int lock_vg(struct local_client *client)struct clvm_header *header = (struct clvm_header *) client->bits.localsock.cmd;unsigned char lock_cmd; -unsigned char lock_flags;int lock_mode;char *args = header->node +strlen (header->node) +1 ;int lkid;
@@ -204,7 +203,6 @@ static int lock_vg(struct local_client *client) lock_cmd = args[0 ] & (LCK_NONBLOCK |LCK_HOLD |LCK_SCOPE_MASK |LCK_TYPE_MASK ); lock_mode = ((int )lock_cmd &LCK_TYPE_MASK ); - lock_flags = args[1 ]; lockname = &args[2 ];DEBUGLOG ("doing PRE command LOCK_VG '%s' at %x (client=%p)\n" , lockname, lock_cmd, client);
Signature · 1 line
1.7.3.4
PATCH 5/23 Remove dead assignment in vgconvert_single
In reply to Zdenek Kabelac'pe_end' is not used - remove it.
--- tools/vgconvert.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
tools/vgconvert.c +1 -3
@@ -26,7 +26,7 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,struct dm_list mdas;int pvmetadatacopies =0 ;uint64_t pvmetadatasize =0 ; -uint64_t pe_end =0 , pe_start =0 ; +uint64_t pe_start =0 ;struct pv_list *pvl;int change_made =0 ;struct lvinfo info;
@@ -119,8 +119,6 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name, existing_pv = pvl->pv; pe_start =pv_pe_start (existing_pv); - pe_end =pv_pe_count (existing_pv) *pv_pe_size (existing_pv) - + pe_start -1 ;dm_list_init (&mdas); if (!(pv = pv_create(cmd, pv_dev(existing_pv),
Signature · 1 line
1.7.3.4
PATCH 6/23 Log of pthread_join operation
In reply to Zdenek KabelacValue jstat is unused - so replace it with logging via log_sys_error().
--- daemons/clvmd/clvmd.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-)
daemons/clvmd/clvmd.c +7 -6
@@ -666,7 +666,6 @@ static int local_pipe_callback(struct local_client *thisfd, char *buf,/* EOF on pipe or an error, close it */ if (len <=0 ) { -int jstat;void *ret = &status;close (thisfd->fd);
@@ -677,7 +676,9 @@ static int local_pipe_callback(struct local_client *thisfd, char *buf,/* Reap child thread */ if (thisfd->bits.pipe.threadid) { - jstat =pthread_join (thisfd->bits.pipe.threadid, &ret); +if (pthread_join (thisfd->bits.pipe.threadid, &ret)) +log_sys_error ("pthread_join" ,"" ); + thisfd->bits.pipe.threadid =0 ;if (thisfd->bits.pipe.client !=NULL ) thisfd->bits.pipe.client->bits.localsock.
@@ -1039,7 +1040,6 @@ static int read_from_local_sock(struct local_client *thisfd)/* EOF or error on socket */ if (len <=0 ) {int *status; -int jstat;DEBUGLOG ("EOF on local socket: inprogress=%d\n" , thisfd->bits.localsock.in_progress);
@@ -1066,9 +1066,10 @@ static int read_from_local_sock(struct local_client *thisfd)pthread_cond_signal (&thisfd->bits.localsock.cond);pthread_mutex_unlock (&thisfd->bits.localsock.mutex); - jstat = -pthread_join (thisfd->bits.localsock.threadid, - (void **) &status); +if (pthread_join (thisfd->bits.localsock.threadid, + (void **) &status)) +log_sys_error ("pthread_join" ,"" ); +DEBUGLOG ("Joined child thread\n" ); thisfd->bits.localsock.threadid =0 ;
Signature · 1 line
1.7.3.4
PATCH 7/23 Move lastfd handling into for()
In reply to Zdenek KabelacWARNING - unclear code.
The loop inside for() works with assumption lastfd would be defined when internal 'if' branches are taken.
Patch adds check for the case lastfd was not yet defined - i.e. removeme of the first element in the list (code itself should be probably switched to standard dm_list?)
Quoted 1 line
From the code reading it's not quite clear how the code should work and
if the case could actually ever happen.
As I'm not familiar with CLVMD logic here - it's probably for someone with better knowledge to decide what is the right step here.
Other solution could be - to check 'lastfd' before if() and continue for the first loop - i.e. expecting at least 2 members in list ?
--- daemons/clvmd/clvmd.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
daemons/clvmd/clvmd.c +6 -4
@@ -826,7 +826,8 @@ static void main_loop(int local_sock, int cmd_timeout)if (thisfd->removeme) {struct local_client *free_fd; - lastfd->next = thisfd->next; +if (lastfd) + lastfd->next = thisfd->next; free_fd = thisfd;DEBUGLOG ("removeme set for fd %d\n" , free_fd->fd);
@@ -861,7 +862,8 @@ static void main_loop(int local_sock, int cmd_timeout)DEBUGLOG ("ret == %d, errno = %d. removing client\n" , ret, errno); - lastfd->next = thisfd->next; +if (lastfd) + lastfd->next = thisfd->next; free_fd = thisfd;safe_close (&(free_fd->fd));
@@ -1092,8 +1094,8 @@ static int read_from_local_sock(struct local_client *thisfd) pipe_client == newfd) { thisfd->bits.localsock. pipe_client =NULL ; - - lastfd->next = newfd->next; +if (lastfd) + lastfd->next = newfd->next; free_fd = newfd; newfd->next = lastfd;free (free_fd);
Signature · 1 line
1.7.3.4
PATCH 8/23 Fix memory leak in error path of restart_clvmd
In reply to Zdenek KabelacMinor memory leak in debug mode.
--- daemons/clvmd/clvmd-command.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
daemons/clvmd/clvmd-command.c +1 -0
@@ -406,6 +406,7 @@ out:for (i =0 ; i < argc && argv[i]; i++)free (argv[i]);free (argv); +free (debug_arg);return 0 ; }
Signature · 1 line
1.7.3.4
PATCH 9/23 Add test for errors in _setup_task
In reply to Zdenek Kabelac--- lib/activate/dev_manager.c | 19 +++++++++++-------- 1 files changed, 11 insertions(+), 8 deletions(-)
lib/activate/dev_manager.c +11 -8
@@ -75,19 +75,22 @@ static struct dm_task *_setup_task(const char *name, const char *uuid,if (!(dmt =dm_task_create (task))) return_NULL; -if (name) -dm_task_set_name (dmt, name); +if (name && !dm_task_set_name (dmt, name)) + goto_out; -if (uuid && *uuid) -dm_task_set_uuid (dmt, uuid); +if (uuid && *uuid && !dm_task_set_uuid (dmt, uuid)) + goto_out; -if (event_nr) -dm_task_set_event_nr (dmt, *event_nr); +if (event_nr && !dm_task_set_event_nr (dmt, *event_nr)) + goto_out; -if (major) -dm_task_set_major_minor (dmt, major, minor,1 ); +if (major && !dm_task_set_major_minor (dmt, major, minor,1 )) + goto_out;return dmt; + out: +dm_task_destroy (dmt); +return NULL ; } static int _info_run(const char *name, const char *dlid, struct dm_info *info,
Signature · 1 line
1.7.3.4
PATCH 10/23 Fix memory leak of dev_filter on error path
In reply to Zdenek KabelacIf the allocation of peristent filter fails - its memory reference is lost.
Also fix log_error message for failing allocation and add proper destroy call on error path.
--- lib/commands/toolcontext.c | 2 ++ lib/filters/filter-persistent.c | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-)
lib/commands/toolcontext.c +2 -0
@@ -707,6 +707,7 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache cache_dir ? "" : "/", cache_dir ? : DEFAULT_CACHE_SUBDIR, cache_file_prefix ? : DEFAULT_CACHE_FILE_PREFIX) < 0) { + f3->destroy (f3);log_error ("Persistent cache filename too long." );return 0 ; }
@@ -715,6 +716,7 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache "%s/%s/%s.cache", cmd->system_dir, DEFAULT_CACHE_SUBDIR, DEFAULT_CACHE_FILE_PREFIX) < 0)) { + f3->destroy (f3);log_error ("Persistent cache filename too long." );return 0 ; }
lib/filters/filter-persistent.c +15 -7
@@ -318,13 +318,16 @@ struct dev_filter *persistent_filter_create(struct dev_filter *real,struct dev_filter *f =NULL ;struct stat info; -if (!(pf =dm_zalloc (sizeof (*pf)))) - return_NULL; +if (!(pf =dm_zalloc (sizeof (*pf)))) { +log_error ("Allocation of persistent filter failed." ); + goto fail; + } -if (!(pf->file =dm_malloc (strlen (file) +1 ))) - goto_bad; +if (!(pf->file =dm_strdup (file))) { +log_error ("Filename duplication for persistent filter failed." ); + goto bad; + } -strcpy (pf->file, file); pf->real = real;if (!(_init_hash (pf))) {
@@ -332,8 +335,10 @@ struct dev_filter *persistent_filter_create(struct dev_filter *real, goto bad; } -if (!(f =dm_malloc (sizeof (*f)))) - goto_bad; +if (!(f =dm_malloc (sizeof (*f)))) { +log_error ("Allocation of device filter for persistent filter failed." ); + goto bad; + }/* Only merge cache file before dumping it if it changed externally. */ if (!stat (pf->file, &info))
@@ -352,5 +357,8 @@ struct dev_filter *persistent_filter_create(struct dev_filter *real,dm_hash_destroy (pf->devices);dm_free (pf);dm_free (f); + + fail: + real->destroy (real);return NULL ; }
Signature · 1 line
1.7.3.4
PATCH 11/23 Add stack traces for archive
In reply to Zdenek KabelacIf archive of back_locally fails - add stack trace.
--- lib/format_text/archiver.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
lib/format_text/archiver.c +6 -3
@@ -452,9 +452,12 @@ void check_current_backup(struct volume_group *vg)log_suppress (old_suppress);if (vg_backup) { -archive (vg_backup); +if (!archive (vg_backup)) + stack;free_vg (vg_backup); } -archive (vg); -backup_locally (vg); +if (!archive (vg)) + stack; +if (!backup_locally (vg)) + stack; }
Signature · 1 line
1.7.3.4
PATCH 12/23 Add tests for dm_task_set operations
In reply to Zdenek KabelacCheck for errors in dm_task_set calls and use goto_bad macro with stack Replace label failed: with bad:
--- daemons/dmeventd/libdevmapper-event.c | 27 +++++++++++++++------------ 1 files changed, 15 insertions(+), 12 deletions(-)
daemons/dmeventd/libdevmapper-event.c +15 -12
@@ -538,34 +538,37 @@ static struct dm_task *_get_device_info(const struct dm_event_handler *dmevh)return NULL ; } -if (dmevh->uuid) -dm_task_set_uuid (dmt, dmevh->uuid); -else if (dmevh->dev_name) -dm_task_set_name (dmt, dmevh->dev_name); -else if (dmevh->major && dmevh->minor) { -dm_task_set_major (dmt, dmevh->major); -dm_task_set_minor (dmt, dmevh->minor); - } +if (dmevh->uuid) { +if (!dm_task_set_uuid (dmt, dmevh->uuid)) + goto_bad; + }else if (dmevh->dev_name) { +if (!dm_task_set_name (dmt, dmevh->dev_name)) + goto_bad; + }else if (dmevh->major && dmevh->minor) { +if (!dm_task_set_major (dmt, dmevh->major) || + !dm_task_set_minor (dmt, dmevh->minor)) + goto_bad; + }/* FIXME Add name or uuid or devno to messages */ if (!dm_task_run (dmt)) {log_error ("_get_device_info: dm_task_run() failed" ); - goto failed; + goto bad; }if (!dm_task_get_info (dmt, &info)) {log_error ("_get_device_info: failed to get info for device" ); - goto failed; + goto bad; }if (!info.exists) {log_error ("_get_device_info: device not found" ); - goto failed; + goto bad; }return dmt; -failed: + bad:dm_task_destroy (dmt);return NULL ; }
Signature · 1 line
1.7.3.4
PATCH 13/23 Make it obvious this code is not used
In reply to Zdenek KabelacStatic analyzis and lcov likes to know this code is unused.
--- lib/activate/dev_manager.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
lib/activate/dev_manager.c +2 -0
@@ -309,6 +309,7 @@ static const struct dm_info *_cached_info(struct dm_pool *mem,return dinfo; } +#if 0 /* FIXME Interface must cope with multiple targets */ static int _status_run(const char *name, const char *uuid, unsigned long long *s, unsigned long long *l,
@@ -386,6 +387,7 @@ static int _status(const char *name, const char *uuid, return 0; } +#endif int lv_has_target_type (struct dm_pool *mem,struct logical_volume *lv,const char *layer,const char *target_type)
Signature · 1 line
1.7.3.4
PATCH 14/23 Add stack trace for backup and backup_remove
In reply to Zdenek KabelacAdd missing 'stack' traces for errors.
--- lib/metadata/metadata.c | 3 ++- tools/vgrename.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-)
lib/metadata/metadata.c +2 -1
@@ -611,7 +611,8 @@ int vg_remove(struct volume_group *vg) } } -backup_remove (vg->cmd, vg->name); +if (!backup_remove (vg->cmd, vg->name)) + stack;if (ret)log_print ("Volume group \"%s\" successfully removed" , vg->name);
tools/vgrename.c +4 -2
@@ -164,8 +164,10 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path, } } -backup (vg); -backup_remove (cmd, vg_name_old); +if (!backup (vg)) + stack; +if (!backup_remove (cmd, vg_name_old)) + stack;unlock_vg (cmd, vg_name_new);unlock_and_free_vg (cmd, vg, vg_name_old);
Signature · 1 line
1.7.3.4
PATCH 15/23 Add test check for find_config_str
In reply to Zdenek KabelacIt looks like there should be some error code returned from _read_desc when something fails.
--- lib/format_text/import_vsn1.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
lib/format_text/import_vsn1.c +2 -2
@@ -842,9 +842,9 @@ static void _read_desc(struct dm_pool *mem, old_suppress =log_suppress (1 ); d =find_config_str (cft->root,"description" ,"" );log_suppress (old_suppress); - *desc =dm_pool_strdup (mem, d); + *desc = (d) ?dm_pool_strdup (mem, d) :NULL ; -get_config_uint32 (cft->root,"creation_time" , &u); + (void )get_config_uint32 (cft->root,"creation_time" , &u); *when = u; }
Signature · 1 line
1.7.3.4
PATCH 16/23 Remove check for vg != NULL
In reply to Zdenek KabelacChecking for vg being != NULL in this place is not needed. We are derefercing vg already in this function above this code line. Also the function _read_pv is always called with 'vg' assigned some valid pointer.
--- lib/format_text/import_vsn1.c | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-)
lib/format_text/import_vsn1.c +6 -8
@@ -257,14 +257,12 @@ static int _read_pv(struct format_instance *fid, struct dm_pool *mem,log_verbose ("Fixing up missing size (%s) " "for PV %s" ,display_size (fid->fmt->cmd, pv->size),pv_dev_name (pv)); -if (vg) { - size = pv->pe_count * (uint64_t ) vg->extent_size + - pv->pe_start; -if (size > pv->size) -log_warn ("WARNING: Physical Volume %s is too " -"large for underlying device" , -pv_dev_name (pv)); - } + size = pv->pe_count * (uint64_t ) vg->extent_size + + pv->pe_start; +if (size > pv->size) +log_warn ("WARNING: Physical Volume %s is too " +"large for underlying device" , +pv_dev_name (pv)); }if (!alloc_pv_segment_whole_pv (mem, pv))
Signature · 1 line
1.7.3.4
PATCH 17/23 Add check for dm_snprintf result
In reply to Zdenek KabelacCheck whether dm_snprintf() was successfull.
For cluster lock use one dm_snprintf() instead of two calls with just one different letter. (For file lock we print different resouce string for P_ - skiping '#' sign - is that needed ?
--- lib/locking/cluster_locking.c | 14 ++++++++------ lib/locking/file_locking.c | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 10 deletions(-)
lib/locking/cluster_locking.c +8 -6
@@ -409,12 +409,14 @@ int lock_resource(struct cmd_context *cmd, const char *resource, uint32_t flags) }/* If the VG name is empty then lock the unused PVs */ -if (is_orphan_vg (resource) ||is_global_vg (resource) || (flags &LCK_CACHE )) -dm_snprintf (lockname,sizeof (lockname),"P_%s" , - resource); -else -dm_snprintf (lockname,sizeof (lockname),"V_%s" , - resource); +if (dm_snprintf (lockname,sizeof (lockname),"%c_%s" , + (is_orphan_vg (resource) || +is_global_vg (resource) || + (flags &LCK_CACHE )) ?'P' :'V' , + resource) <0 ) { +log_error ("Locking resource %s too long." , resource); +return 0 ; + } lock_scope ="VG" ; clvmd_cmd =CLVMD_CMD_LOCK_VG ;
lib/locking/file_locking.c +12 -4
@@ -269,11 +269,19 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource,break ;if (is_orphan_vg (resource) ||is_global_vg (resource)) -dm_snprintf (lockfile,sizeof (lockfile), -"%s/P_%s" , _lock_dir, resource +1 ); +if (dm_snprintf (lockfile,sizeof (lockfile), +"%s/P_%s" , _lock_dir, resource +1 ) <0 ) { +log_error ("Too long locking filename %s/P_%s." , + _lock_dir, resource +1 ); +return 0 ; + }else -dm_snprintf (lockfile,sizeof (lockfile), -"%s/V_%s" , _lock_dir, resource); +if (dm_snprintf (lockfile,sizeof (lockfile), +"%s/V_%s" , _lock_dir, resource) <0 ) { +log_error ("Too long locking filename %s/V_%s." , + _lock_dir, resource); +return 0 ; + }if (!_lock_file (lockfile, flags)) return_0;
Signature · 1 line
1.7.3.4
PATCH 18/23 Return PERCENT_INVALID for error case
In reply to Zdenek KabelacIf the percent value could not be determined - return PERCENT_INVALD. Indent function with tabs.
--- lib/report/properties.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
lib/report/properties.c +9 -6
@@ -87,15 +87,18 @@ static int _not_implemented_set(void *obj, struct lvm_property_type *prop) }static percent_t _copy_percent (const struct logical_volume *lv) { -percent_t perc; -lv_mirror_percent (lv->vg->cmd, (struct logical_volume *) lv,0 , &perc,NULL ); -return perc; +percent_t perc; +if (!lv_mirror_percent (lv->vg->cmd, (struct logical_volume *) lv, +0 , &perc,NULL )) + perc =PERCENT_INVALID ; +return perc; }static percent_t _snap_percent (const struct logical_volume *lv) { -percent_t perc; -lv_snapshot_percent (lv, &perc); -return perc; +percent_t perc; +if (!lv_snapshot_percent (lv, &perc)) + perc =PERCENT_INVALID ; +return perc; }/* PV */
Signature · 1 line
1.7.3.4
PATCH 19/23 Warning - dead code problem elimination
In reply to Zdenek KabelacOriginal code assign ret = DM_WAIT_INTR and immediately reassing this value with result code from dm_task_get_info.
It's not quite clear how such result code is supposed to fit DM_WAIT defines used in this function (maybe wrong merge?)
Maybe it's actually wrong to assing ret with dm_task_get_info. So reather then removing line: ret = DM_WAIT_INTR patch removes later assignment.
CHECKME!!!
--- daemons/dmeventd/dmeventd.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
daemons/dmeventd/dmeventd.c +1 -2
@@ -653,8 +653,7 @@ static int _event_wait(struct thread_status *thread, struct dm_task **task)if (dm_task_run (dmt)) { thread->current_events |=DM_EVENT_DEVICE_ERROR ; ret =DM_WAIT_INTR ; - -if ((ret =dm_task_get_info (dmt, &info))) +if (dm_task_get_info (dmt, &info)) thread->event_nr = info.event_nr; }else if (thread->events &DM_EVENT_TIMEOUT && errno ==EINTR ) { thread->current_events |=DM_EVENT_TIMEOUT ;
Signature · 1 line
1.7.3.4
PATCH 20/23 exit if lvmchache_init fails
In reply to Zdenek Kabelac--- tools/polldaemon.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
tools/polldaemon.c +2 -1
@@ -64,7 +64,8 @@ static int _become_daemon(struct cmd_context *cmd)strncpy (*cmd->argv,"(lvm2)" ,strlen (*cmd->argv));reset_locking (); -lvmcache_init (); +if (!lvmcache_init ()) +_exit (ECMD_FAILED );dev_close_all ();return 1 ;
Signature · 1 line
1.7.3.4
PATCH 21/23 Add default error path for get_property
In reply to Zdenek KabelacSet invalid property value for error path when none of handlers is set. Fixes use of uninitialized prop variable.
Maybe add log_error() for this programming error?
--- liblvm/lvm_misc.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
liblvm/lvm_misc.c +4 -0
@@ -78,7 +78,11 @@ struct lvm_property_value get_property(const pv_t pv, const vg_t vg, v.is_valid =0 ;return v; } + }else { + v.is_valid =0 ; +return v; } + v.is_settable = prop.is_settable; v.is_string = prop.is_string; v.is_integer = prop.is_integer;
Signature · 1 line
1.7.3.4
PATCH 22/23 Remove dead assignment in dm_event_get_registered_device
In reply to Zdenek Kabelacret assigned from _do_event was actually not used and replaced with next assignment without any read of returned value.
Code is reformated - so error path is put in the if branch and normal code is put after the 'if' together with FIXME comment.
--- daemons/dmeventd/libdevmapper-event.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
daemons/dmeventd/libdevmapper-event.c +7 -7
@@ -718,17 +718,17 @@ int dm_event_get_registered_device(struct dm_event_handler *dmevh, int next) uuid =dm_task_get_uuid (dmt); -if (!(ret =_do_event (next ?DM_EVENT_CMD_GET_NEXT_REGISTERED_DEVICE : -DM_EVENT_CMD_GET_REGISTERED_DEVICE , dmevh->dmeventd_path, - &msg, dmevh->dso, uuid, dmevh->mask,0 ))) { -/* FIXME this will probably horribly break if we get -ill-formatted reply */ - ret =_parse_message (&msg, &reply_dso, &reply_uuid, &reply_mask); - }else { +if (_do_event (next ?DM_EVENT_CMD_GET_NEXT_REGISTERED_DEVICE : +DM_EVENT_CMD_GET_REGISTERED_DEVICE , dmevh->dmeventd_path, + &msg, dmevh->dso, uuid, dmevh->mask,0 )) { ret = -ENOENT ; goto fail; } +/* FIXME this will probably horribly break if we get +ill-formatted reply */ + ret =_parse_message (&msg, &reply_dso, &reply_uuid, &reply_mask); +dm_task_destroy (dmt); dmt =NULL ;
Signature · 1 line
1.7.3.4
PATCH 23/23 Remove dead assignment in vg_split_mdas
In reply to Zdenek Kabelac'common_mda' is assigned again with next code line.
Why is the result not important from the first call? CHECKME!
--- lib/metadata/metadata.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
lib/metadata/metadata.c +2 -3
@@ -1263,15 +1263,14 @@ int vg_split_mdas(struct cmd_context *cmd __attribute__((unused)), {struct dm_list *mdas_from_in_use, *mdas_to_in_use;struct dm_list *mdas_from_ignored, *mdas_to_ignored; -int common_mda =0 ; +int common_mda; mdas_from_in_use = &vg_from->fid->metadata_areas_in_use; mdas_from_ignored = &vg_from->fid->metadata_areas_ignored; mdas_to_in_use = &vg_to->fid->metadata_areas_in_use; mdas_to_ignored = &vg_to->fid->metadata_areas_ignored; - common_mda =_move_mdas (vg_from, vg_to, - mdas_from_in_use, mdas_to_in_use); +_move_mdas (vg_from, vg_to, mdas_from_in_use, mdas_to_in_use); common_mda =_move_mdas (vg_from, vg_to, mdas_from_ignored, mdas_to_ignored);
Signature · 1 line
1.7.3.4
PATCH 4/23 Remove dead assignment of lock_flags
In reply to Zdenek Kabelacdaemons/clvmd/clvmd-command.c static int lock_vg(struct local_client *client) · line 206
Quoted 6 lines · Zdenek Kabelac
daemons/clvmd/clvmd-command.c +0
-1@@ -204,7 +203,6 @@ static int lock_vg(struct local_client *client) lock_cmd = args[0 ] & (LCK_NONBLOCK |LCK_HOLD |LCK_SCOPE_MASK |LCK_TYPE_MASK ); lock_mode = ((int )lock_cmd &LCK_TYPE_MASK ); - lock_flags = args[1 ]; lockname = &args[2 ];
I intentionally kept unused args[1] here because it is clear how the request look like without searching code, IOW
- 0 byte is command
- 1 byte flags
- 2 lockname
So any possible changes is easy on place.
Yes, it should be struct and should use some friendly names. But now there is byte array...
Complier is clever enough to remove that code.
I do not care what some stupid static analysis says, the code is more readable with "dead" variable for me.
Milan
PATCH 7/23 Move lastfd handling into for()
In reply to Zdenek Kabelacdaemons/clvmd/clvmd.c static void main_loop(int local_sock, int cmd_timeout) · line 830
Quoted 7 lines · Zdenek Kabelac
daemons/clvmd/clvmd.c +2
-1@@ -826,7 +826,8 @@ static void main_loop(int local_sock, int cmd_timeout)if (thisfd->removeme) {struct local_client *free_fd; - lastfd->next = thisfd->next; +if (lastfd) + lastfd->next = thisfd->next;
Isn't that replacing one bug with another?
If lastfd is NULL, it will crash.
After your change it will quietly do something, apparently with wrong pointers.
If lastfd cannot be NULL, the check is not needed and is redundant.
I *think* that the first fd in select is local one, removing itself is nonsense, so lastfd should be always set. (lastfd is set in the for cycle)
Anyway I prefer to keep the code intact instead of hiding possible bug.
(Or rewrite it to something more readable. e.g. removeme flag seems to be used only in gulm code, which is dead and unsupported etc)
Milan
PATCH 9/23 Add test for errors in _setup_task
In reply to Zdenek Kabelaclib/activate/dev_manager.c static struct dm_task *_setup_task(const char *name, const char *uuid, · line 82
Quoted 4 lines · Zdenek Kabelac
lib/activate/dev_manager.c +2
-2-if (uuid && *uuid) -dm_task_set_uuid (dmt, uuid); +if (uuid && *uuid && !dm_task_set_uuid (dmt, uuid)) + goto_out;
Shouldn't it fail if uuid is requested but it is empty string? (but that's another problem:-)
Milan
PATCH 10/23 Fix memory leak of dev_filter on error path
In reply to Zdenek Kabelaclib/filters/filter-persistent.c struct dev_filter *persistent_filter_create(struct dev_filter *real, · line 364
Quoted 9 lines · Zdenek Kabelac
lib/filters/filter-persistent.c +3
-0@@ -352,5 +357,8 @@ struct dev_filter *persistent_filter_create(struct dev_filter *real,dm_hash_destroy (pf->devices);dm_free (pf);dm_free (f); + + fail: + real->destroy (real);return NULL ; }
Why not move it to the caller instead - the same like previous two?
if (!(f4 = persistent_filter_create(f3, dev_cache))) {
log_error("Failed to create persistent device filter");
+ f3->destroy(f3);
return 0;
}Milan
PATCH 15/23 Add test check for find_config_str
In reply to Zdenek Kabelaclib/format_text/import_vsn1.c static void _read_desc(struct dm_pool *mem, · line 845
Quoted 2 lines · Zdenek Kabelac
lib/format_text/import_vsn1.c +1
-1- *desc =dm_pool_strdup (mem, d); + *desc = (d) ?dm_pool_strdup (mem, d) :NULL ;
dm_pool_strdup(NULL) tries to alloc 1 byte and returning pointer, and not setting to \0 and calling strlen(NULL).
dunno what was the intention here.
lib/format_text/import_vsn1.c static void _read_desc(struct dm_pool *mem, · line 847
Quoted 2 lines
lib/format_text/import_vsn1.c +1
-1-get_config_uint32 (cft->root,"creation_time" , &u); + (void )get_config_uint32 (cft->root,"creation_time" , &u);
What's wrong here? I thought that this is needed only if is defined with warn_if_unused_result?
Milan
PATCH 17/23 Add check for dm_snprintf result
In reply to Zdenek KabelacQuoted 5 lines
lib/locking/cluster_locking.c +0
-4/* If the VG name is empty then lock the unused PVs */ -if (is_orphan_vg (resource) ||is_global_vg (resource) || (flags &LCK_CACHE )) -dm_snprintf (lockname,sizeof (lockname),"P_%s" , - resource); -else
lib/locking/cluster_locking.c int lock_resource(struct cmd_context *cmd, const char *resource, uint32_t flags) · line 419
Quoted 10 lines
lib/locking/cluster_locking.c +8
-2-dm_snprintf (lockname,sizeof (lockname),"V_%s" , - resource); +if (dm_snprintf (lockname,sizeof (lockname),"%c_%s" , + (is_orphan_vg (resource) || +is_global_vg (resource) || + (flags &LCK_CACHE )) ?'P' :'V' , + resource) <0 ) { +log_error ("Locking resource %s too long." , resource); +return 0 ; + }
I cannot imagine how this can happen. First parm is fixed char, second is resource string with exact length. And char lockname[PATH_MAX];
Should we check for glibc and clompiler bugs also? :)
Well, isn't return_0 here enough?
Milan
PATCH 18/23 Return PERCENT_INVALID for error case
In reply to Zdenek Kabelaclib/report/properties.c static int _not_implemented_set(void *obj, struct lvm_property_type *prop) · line 94
Quoted 4 lines · Zdenek Kabelac
lib/report/properties.c +4
-0+if (!lv_mirror_percent (lv->vg->cmd, (struct logical_volume *) lv, +0 , &perc,NULL )) + perc =PERCENT_INVALID ; +return perc;
dunno, these functions returns 0 if (!activation()) and if lv is not activated
is the PERCENT_INVALID (-1) correct value here?
But it is apparent bug, it returns undefined value in API now.
Milan
PATCH 19/23 Warning - dead code problem elimination
In reply to Zdenek Kabelacdaemons/dmeventd/dmeventd.c static int _event_wait(struct thread_status *thread, struct dm_task **task) · line 659
Quoted 10 lines · Zdenek Kabelac
daemons/dmeventd/dmeventd.c +1
-2@@ -653,8 +653,7 @@ static int _event_wait(struct thread_status *thread, struct dm_task **task)if (dm_task_run (dmt)) { thread->current_events |=DM_EVENT_DEVICE_ERROR ; ret =DM_WAIT_INTR ; - -if ((ret =dm_task_get_info (dmt, &info))) +if (dm_task_get_info (dmt, &info)) thread->event_nr = info.event_nr; }else if (thread->events &DM_EVENT_TIMEOUT && errno ==EINTR ) { thread->current_events |=DM_EVENT_TIMEOUT ;
#define DM_WAIT_RETRY 0
#define DM_WAIT_INTR 1
dm_task_get_info returns 0/1 - it is probably intended such way?
I think you should return DM_WAIT_RETRY if info fails then (so the code _was_ correct)?
mornfall? :)
Milan
cover Static analyzis set
In reply to Zdenek KabelacQuoted 2 lines · Zdenek Kabelac
This is mostly the last bigger patch sets for covering issues reported by Coverity tool.
If it help to stop spamming list, my ACK for:
2,3,6,8,9,11,12,13,14,16,20,21,22,23
(No, these are not numbers from National Lottery and you did not won $1,000,000:-)
others I do not like but but do not care (no comment) or ... see comment:)
Milan
PATCH 19/23 Warning - dead code problem elimination
In reply to Milan BrozQuoted 15 lines · Milan Broz
daemons/dmeventd/dmeventd.c static int _event_wait(struct thread_status *thread, struct dm_task **task) · line 659
Quoted 10 lines · Zdenek Kabelac
daemons/dmeventd/dmeventd.c +1
-2@@ -653,8 +653,7 @@ static int _event_wait(struct thread_status *thread, struct dm_task **task)if (dm_task_run (dmt)) { thread->current_events |=DM_EVENT_DEVICE_ERROR ; ret =DM_WAIT_INTR ; - -if ((ret =dm_task_get_info (dmt, &info))) +if (dm_task_get_info (dmt, &info)) thread->event_nr = info.event_nr; }else if (thread->events &DM_EVENT_TIMEOUT && errno ==EINTR ) { thread->current_events |=DM_EVENT_TIMEOUT ;#define
DM_WAIT_RETRY0
#defineDM_WAIT_INTR1
Quoted 5 lines
dm_task_get_inforeturns 0/1 - it is probably intended such way?I think you should return
DM_WAIT_RETRYif info fails then (so the code _was_ correct)?mornfall? :)
Jeez, I wish I knew! I don't think I wrote this code. Anyway, it would make sense to add ret = DM_WAIT_RETRY in the else branch (i.e. get_info fails). Not that this is likely to ever trigger...
Petr
PATCH 15/23 Add test check for find_config_str
In reply to Milan BrozDne 21.12.2010 18:32, Milan Broz napsal(a):
Quoted 7 lines · Zdenek Kabelac
lib/format_text/import_vsn1.c static void _read_desc(struct dm_pool *mem, · line 845
Quoted 3 lines
lib/format_text/import_vsn1.c +1
-1- *desc =dm_pool_strdup (mem, d); + *desc = (d) ?dm_pool_strdup (mem, d) :NULL ;
dm_pool_strdup(NULL)tries to alloc 1 byte and returning pointer, and not setting to \0 and calling strlen(NULL).
hmm libdm/mm/pool.c - line 30
It looks like fault case.
Quoted 9 lines
dunno what was the intention here.
lib/format_text/import_vsn1.c static void _read_desc(struct dm_pool *mem, · line 847
Quoted 2 lines
lib/format_text/import_vsn1.c +1
-1-get_config_uint32 (cft->root,"creation_time" , &u); + (void )get_config_uint32 (cft->root,"creation_time" , &u);What's wrong here? I thought that this is needed only if is defined with
warn_if_unused_result?
When we ignore return value - we should do that explicitly when we test all other cases - it's being reported as suspicious.
IMHO more important question here is - if it's correct to have this function returning void.
Zdenek
PATCH 10/23 Fix memory leak of dev_filter on error path
In reply to Milan BrozDne 21.12.2010 18:21, Milan Broz napsal(a):
Quoted 17 lines · Zdenek Kabelac
lib/filters/filter-persistent.c struct dev_filter *persistent_filter_create(struct dev_filter *real, · line 364
Quoted 10 lines
lib/filters/filter-persistent.c +3
-0@@ -352,5 +357,8 @@ struct dev_filter *persistent_filter_create(struct dev_filter *real,dm_hash_destroy (pf->devices);dm_free (pf);dm_free (f); + + fail: + real->destroy (real);return NULL ; }Why not move it to the caller instead - the same like previous two?
if (!(f4 = persistent_filter_create(f3, dev_cache))) { log_error("Failed to create persistent device filter");(quoted diff) +1
-0+ f3->destroy(f3);
Quoted 3 lines
return 0; }
I'm not sure about the best logic - so used this as a plain proposal - of course both variants could be seen as valid. And as I've been already fixing error messages in the function it self, I've put the call of destructor there.
My idea was - one the persistent_filter_create() is called - it takes ownership of the passed struct dev_filter.
Your proposal means - that in error case the function doesn't take responsibility for this value and caller is supposed to cleanup.
Do we agree on this semantic ?
Zdenek
PATCH 4/23 Remove dead assignment of lock_flags
In reply to Milan BrozDne 21.12.2010 17:20, Milan Broz napsal(a):
Quoted 15 lines · Zdenek Kabelac
daemons/clvmd/clvmd-command.c static int lock_vg(struct local_client *client) · line 206
Quoted 6 lines
daemons/clvmd/clvmd-command.c +0
-1@@ -204,7 +203,6 @@ static int lock_vg(struct local_client *client) lock_cmd = args[0 ] & (LCK_NONBLOCK |LCK_HOLD |LCK_SCOPE_MASK |LCK_TYPE_MASK ); lock_mode = ((int )lock_cmd &LCK_TYPE_MASK ); - lock_flags = args[1 ]; lockname = &args[2 ];I intentionally kept unused args[1] here because it is clear how the request look like without searching code, IOW
- 0 byte is command
- 1 byte flags
- 2 lockname
Quoted 7 lines
So any possible changes is easy on place.
Yes, it should be struct and should use some friendly names. But now there is byte array...Complier is clever enough to remove that code.
I do not care what some stupid static analysis says, the code is more readable with "dead" variable for me.
I always thought that's why /* comments */ were invented ;) for things like this, but anyway in this case if you prefer to keep the unused value present - I'll hide it only for my local scan-builds :)
Zdenek
PATCH 7/23 Move lastfd handling into for()
In reply to Milan BrozDne 21.12.2010 17:50, Milan Broz napsal(a):
Quoted 17 lines · Zdenek Kabelac
daemons/clvmd/clvmd.c static void main_loop(int local_sock, int cmd_timeout) · line 830
Quoted 8 lines
daemons/clvmd/clvmd.c +2
-1@@ -826,7 +826,8 @@ static void main_loop(int local_sock, int cmd_timeout)if (thisfd->removeme) {struct local_client *free_fd; - lastfd->next = thisfd->next; +if (lastfd) + lastfd->next = thisfd->next;Isn't that replacing one bug with another?
If lastfd is NULL, it will crash.
After your change it will quietly do something, apparently with wrong pointers.If lastfd cannot be NULL, the check is not needed and is redundant.
Quoted 8 lines
I *think* that the first fd in select is local one, removing itself is nonsense, so lastfd should be always set. (lastfd is set in the for cycle)
Anyway I prefer to keep the code intact instead of hiding possible bug.
(Or rewrite it to something more readable. e.g. removeme flag seems to be used only in gulm code, which is dead and unsupported etc)
The code is really a bit complicated to read in this case - so that's why I've commented the patch that clvmd expert is needed.
Other way around in the patch could be - to simply skip first loop case and assign the first value directly to 'lastfd' and start for() directly with the next element. That would make code more obvious that the list always needs to have at least 2 members.
Other question is - if we do not support gulm anymore - why do we keep unmaintained and untested code ? :)
Zdenek
PATCH 9/23 Add test for errors in _setup_task
In reply to Milan BrozDne 21.12.2010 18:12, Milan Broz napsal(a):
Quoted 9 lines · Zdenek Kabelac
lib/activate/dev_manager.c static struct dm_task *_setup_task(const char *name, const char *uuid, · line 82
Quoted 4 lines
lib/activate/dev_manager.c +2
-2-if (uuid && *uuid) -dm_task_set_uuid (dmt, uuid); +if (uuid && *uuid && !dm_task_set_uuid (dmt, uuid)) + goto_out;Shouldn't it fail if uuid is requested but it is empty string? (but that's another problem:-)
If this is invalid combination:
(uuid && (!*uuid || !dm_task_set_uuid())
Zdenek
PATCH 17/23 Add check for dm_snprintf result
In reply to Milan BrozDne 21.12.2010 18:38, Milan Broz napsal(a):
Quoted 10 lines
Quoted 10 lines
lib/locking/cluster_locking.c +3
-6/* If the VG name is empty then lock the unused PVs */ -if (is_orphan_vg (resource) ||is_global_vg (resource) || (flags &LCK_CACHE )) -dm_snprintf (lockname,sizeof (lockname),"P_%s" , - resource); -else -dm_snprintf (lockname,sizeof (lockname),"V_%s" , - resource); + if (dm_snprintf(lockname, sizeof(lockname), "%c_%s", + (is_orphan_vg(resource) || + is_global_vg(resource) ||
Quoted 8 lines
lib/locking/cluster_locking.c int lock_resource(struct cmd_context *cmd, const char *resource, uint32_t flags) · line 419
Quoted 5 lines
lib/locking/cluster_locking.c +5
-0+ (flags & LCK_CACHE)) ? 'P' : 'V', + resource) < 0) { +log_error ("Locking resource %s too long." , resource); +return 0 ; + }I cannot imagine how this can happen. First parm is fixed char, second is resource string with exact length. And char lockname[PATH_MAX];
One shiny afternoon day someone could think about using 256byte long VG and LV uuids and it will nicely fail ;)
So take this just like an assert.
Quoted 5 lines
Should we check for glibc and clompiler bugs also? :)
Well, isn't
return_0here enough?
First trace is supposed to be always some 'log_error'
If you print only 'stack' without log_error - internal error is generated. (Thought we have it wrong on many places in the code...)
Zdenek
PATCH 17/23 Add check for dm_snprintf result
Quoted 10 lines · Zdenek Kabelac
Quoted 10 lines
lib/locking/cluster_locking.c int lock_resource(struct cmd_context *cmd, const char *resource, uint32_t flags) · line 419
Quoted 8 lines
lib/locking/cluster_locking.c +8
-0+if (dm_snprintf (lockname,sizeof (lockname),"%c_%s" , + (is_orphan_vg (resource) || +is_global_vg (resource) || + (flags &LCK_CACHE )) ?'P' :'V' , + resource) <0 ) { +log_error ("Locking resource %s too long." , resource); +return 0 ; + }I cannot imagine how this can happen. First parm is fixed char, second is resource string with exact length. And char lockname[PATH_MAX];
Quoted 2 lines
One shiny afternoon day someone could think about using 256byte long VG and LV uuids and it will nicely fail ;)
I've no objection to adding tests like that, though adding '(void)' in places like this that are safe is also fine.
Alasdair
PATCH 9/23 Add test for errors in _setup_task
In reply to Zdenek KabelacQuoted 9 lines · Zdenek Kabelac
Dne 21.12.2010 18:12, Milan Broz napsal(a):
Quoted 8 lines · Zdenek Kabelac
lib/activate/dev_manager.c static struct dm_task *_setup_task(const char *name, const char *uuid, · line 82
Quoted 4 lines
lib/activate/dev_manager.c +2
-2-if (uuid && *uuid) -dm_task_set_uuid (dmt, uuid); +if (uuid && *uuid && !dm_task_set_uuid (dmt, uuid)) + goto_out;Shouldn't it fail if uuid is requested but it is empty string? (but that's another problem:-)
Is there a case for moving the "Is uuid empty?" test inside dm_task_set_uuid(). IOW if dm_task_set_uuid() is passed an empty string, I think it should erase the existing uuid but not bother to create a new one.
Perhaps?
int dm_task_set_uuid(struct dm_task *dmt, const char *uuid)
{
dm_free(dmt->uuid);
if (!uuid || !*uuid)
return 1;
if (!(dmt->uuid = dm_strdup(uuid))) {
log_error("dm_task_set_uuid: strdup(%s) failed", uuid);
return 0;
}
return 1;
}Alasdair
PATCH 7/23 Move lastfd handling into for()
In reply to Zdenek KabelacQuoted 2 lines · Zdenek Kabelac
Other question is - if we do not support gulm anymore - why do we keep unmaintained and untested code ? :)
If this is gulm-only code, just leave it exactly as it is. No need to try to clean it up or to fix theoretical problems in it unless responding to patches from people using it and trying to fix it.
Alasdair
PATCH 4/23 Remove dead assignment of lock_flags
In reply to Zdenek KabelacQuoted 3 lines · Zdenek Kabelac
I always thought that's why /* comments */ were invented ;) for things like this, but anyway in this case if you prefer to keep the unused value present - I'll hide it only for my local scan-builds :)
So do a patch that moves it into a comment?
Alasdair
PATCH 10/23 Fix memory leak of dev_filter on error path
In reply to Zdenek KabelacQuoted 6 lines · Zdenek Kabelac
I'm not sure about the best logic - so used this as a plain proposal - of course both variants could be seen as valid. And as I've been already fixing error messages in the function it self, I've put the call of destructor there.
My idea was - one the
persistent_filter_create()is called - it takes ownership of the passed structdev_filter.
I don't think it matters which you pick, but add comments to make it clear who's responsible for cleanup.
Alasdair
PATCH 15/23 Add test check for find_config_str
In reply to Zdenek KabelacQuoted 11 lines · Zdenek Kabelac
Quoted 5 lines
lib/format_text/import_vsn1.c static void _read_desc(struct dm_pool *mem, · line 847
Quoted 2 lines
lib/format_text/import_vsn1.c +1
-1-get_config_uint32 (cft->root,"creation_time" , &u); + (void )get_config_uint32 (cft->root,"creation_time" , &u);What's wrong here? I thought that this is needed only if is defined with
warn_if_unused_result?When we ignore return value - we should do that explicitly when we test all other cases - it's being reported as suspicious.
IMHO more important question here is - if it's correct to have this function returning void.
Exactly - the real problem is: what if the field is not present? Well the code seems to permit that:
It uses a description of "" if there's no description, and a time of 0 if there's no creation_time.
So I think (void) was indeed the intention.
Alasdair
PATCH 4/23 Remove dead assignment of lock_flags
In reply to Alasdair G KergonQuoted 6 lines · Alasdair G Kergon
Quoted 3 lines · Zdenek Kabelac
I always thought that's why /* comments */ were invented ;) for things like this, but anyway in this case if you prefer to keep the unused value present - I'll hide it only for my local scan-builds :)
So do a patch that moves it into a comment?
That code is messy, and it should be cleaned - the lock_vg() name is misleading (it should be called pre_lock_vg(), it should take pre-parsed flags and not parse it itself from client struct - the same like lock_lv etc)
So if you think cleaning one variable help anything, better do it than spent another week discussing it :-)
Milan
PATCH 15/23 Add test check for find_config_str
In reply to Zdenek KabelacQuoted 2 lines · Zdenek Kabelac
It looks like there should be some error code returned from
_read_descwhen something fails.
No need - the code is just using default values of "" and 0.
lib/format_text/import_vsn1.c static void _read_desc(struct dm_pool *mem, · line 845
Quoted 2 lines
lib/format_text/import_vsn1.c +1
-1- *desc =dm_pool_strdup (mem, d); + *desc = (d) ?dm_pool_strdup (mem, d) :NULL ;
Superfluous - this follows
d = find_config_str(cft->root, "description", "");
which returns "" on failure so d is never NULL.
Alasdair
PATCH 10/23 Fix memory leak of dev_filter on error path
In reply to Milan BrozQuoted 1 line · Milan Broz
Why not move it to the caller instead - the same like previous two?
Oh, consistency, yes please!
Alasdair
PATCH 7/23 Move lastfd handling into for()
In reply to Milan BrozQuoted 1 line · Milan Broz
Anyway I prefer to keep the code intact instead of hiding possible bug.
Ack, if this is only a gulm thing.
Just add a comment to that effect.
Alasdair
PATCH 5/23 Remove dead assignment in vgconvert_single
In reply to Zdenek Kabelactools/vgconvert.c static int vgconvert_single(struct cmd_context *cmd, const char *vg_name, · line 123
Quoted 5 lines · Zdenek Kabelac
'
pe_end' is not used - remove it.tools/vgconvert.c +0
-2pe_start =pv_pe_start (existing_pv); - pe_end =pv_pe_count (existing_pv) *pv_pe_size (existing_pv) - + pe_start -1 ;
Please retain that formula in a comment instead.
Alasdair
PATCH 20/23 exit if lvmchache_init fails
In reply to Zdenek Kabelactools/polldaemon.c static int _become_daemon(struct cmd_context *cmd) · line 69
Quoted 5 lines · Zdenek Kabelac
tools/polldaemon.c +2
-1reset_locking (); -lvmcache_init (); +if (!lvmcache_init ()) +_exit (ECMD_FAILED );dev_close_all ();
Ack.
Not ideal, but we actually already have some existing tricky cleanup problems here that I never fixed, so just add a FIXME "Clean up properly here!" to that _exit().
Alasdair
PATCH 23/23 Remove dead assignment in vg_split_mdas
In reply to Zdenek Kabelaclib/metadata/metadata.c int vg_split_mdas(struct cmd_context *cmd __attribute__((unused)), · line 1275
Quoted 12 lines · Zdenek Kabelac
'
common_mda' is assigned again with next code line.lib/metadata/metadata.c +1
-2mdas_from_in_use = &vg_from->fid->metadata_areas_in_use; mdas_from_ignored = &vg_from->fid->metadata_areas_ignored; mdas_to_in_use = &vg_to->fid->metadata_areas_in_use; mdas_to_ignored = &vg_to->fid->metadata_areas_ignored; - common_mda =_move_mdas (vg_from, vg_to, - mdas_from_in_use, mdas_to_in_use); +_move_mdas (vg_from, vg_to, mdas_from_in_use, mdas_to_in_use); common_mda =_move_mdas (vg_from, vg_to, mdas_from_ignored, mdas_to_ignored);
Not immediately obvious how this code is correct.
The function returns 0 (giving user error message and aborting the split operation) if common_mda is 0 i.e. if after the split there'll be no mdas in the 'from' VG and there was no 'common' mda on the 'mdas_from_ignored' list.
I'd guess the two lines should be in the opposite order, ignoring the result from the 'ignored' move, but I don't understand why the 'common_mdas' are not also taken into account (ignored) in _vg_adjust_ignored_mdas.
_move_mdas() uses '!mda->ops->mda_in_vg' to detect a common_mda - why are the functions that manipulate which mdas are ignored not also doing this? (This seems to be being used as a flag to indicate 'This mda must always be used and cannot be ignored'.)
Even if the code is correct, it needs to be made clearer what it is doing.
Alasdair
PATCH 9/23 Add test for errors in _setup_task
In reply to Zdenek KabelacAck.
Alasdair
PATCH 21/23 Add default error path for get_property
In reply to Zdenek KabelacQuoted 2 lines · Zdenek Kabelac
Set invalid property value for error path when none of handlers is set. Fixes use of uninitialized prop variable.
Ack.
Quoted 1 line
Maybe add
log_error()for this programming error?
You could probably add a log_errno() for errors with use of the library interface, yes.
Alasdair
PATCH 22/23 Remove dead assignment in dm_event_get_registered_device
In reply to Zdenek KabelacQuoted 2 lines · Zdenek Kabelac
ret assigned from
_do_eventwas actually not used and replaced with next assignment without any read of returned value.
But does the actual error already get logged somewhere? (I don't see where.)
Some _do_event() failures are reported, others aren't. I don't see why there's a distinction.
A DM_EVENT_CMD_REGISTER_FOR_EVENT failure is logged. A DM_EVENT_CMD_GET_TIMEOUT failure is not.
Surely these failures should never occur on a properly-running system, so why not log them all in a similar way?
Alasdair
PATCH 19/23 Warning - dead code problem elimination
In reply to Petr RockaiQuoted 5 lines
Quoted 1 line
I think you should return
DM_WAIT_RETRYif info fails then (so the code _was_ correct)?Jeez, I wish I knew! I don't think I wrote this code. Anyway, it would make sense to add ret =
DM_WAIT_RETRYin the else branch (i.e.get_infofails). Not that this is likely to ever trigger...
Do that then.
Alasdair
PATCH 18/23 Return PERCENT_INVALID for error case
In reply to Milan BrozQuoted 8 lines · Milan Broz
lib/report/properties.c static int _not_implemented_set(void *obj, struct lvm_property_type *prop) · line 94
Quoted 4 lines · Zdenek Kabelac
lib/report/properties.c +4
-0+if (!lv_mirror_percent (lv->vg->cmd, (struct logical_volume *) lv, +0 , &perc,NULL )) + perc =PERCENT_INVALID ; +return perc;dunno, these functions returns 0 if (!activation()) and if lv is not activated
is thePERCENT_INVALID(-1) correct value here?
Seems a reasonable use of this.
Ack (current code is definitely wrong) pending a review of whether all the code is making best use of the values of the new percent type.
Alasdair
PATCH 6/23 Log of pthread_join operation
In reply to Zdenek KabelacQuoted 1 line · Zdenek Kabelac
Value jstat is unused - so replace it with logging via
log_sys_error().
Ack.
Alasdair
PATCH 3/23 Remove dead assigment of mirr_state
In reply to Zdenek KabelacQuoted 1 line · Zdenek Kabelac
Variable '
mirr_state' is not used.
Ack.
Alasdair
PATCH 1/23 Remove dead assignment to thisfd
In reply to Zdenek KabelacQuoted 1 line · Zdenek Kabelac
Value 'thisfd' is not read again after this assigment.
Ack.
Alasdair
PATCH 2/23 Remove dead assignment
In reply to Zdenek KabelacQuoted 1 line · Zdenek Kabelac
Variables '
lv_total' and 'lv_capasity_total' are unused.
Ack.
Probably LVM1 used to display these, but we never bothered to reimplement lvscan fully as there are better commands to use instead.
Alasdair