From patchwork Tue Jul 20 08:10:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 112978 Received: from mx02.colomx.prod.int.phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o6K8CSR0023915 for ; Tue, 20 Jul 2010 08:14:04 GMT Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx02.colomx.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6K8AwE5007058; Tue, 20 Jul 2010 04:10:58 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6K8AjJn019739 for ; Tue, 20 Jul 2010 04:10:45 -0400 Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.12]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6K8AelQ026243 for ; Tue, 20 Jul 2010 04:10:40 -0400 Received: from mx1.suse.de (cantor.suse.de [195.135.220.2]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o6K8AUv1023097 for ; Tue, 20 Jul 2010 04:10:31 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id E4DDE945D6; Tue, 20 Jul 2010 10:10:29 +0200 (CEST) Date: Tue, 20 Jul 2010 10:10:29 +0200 To: Christophe Varoqui User-Agent: Heirloom mailx 12.2 01/07/07 MIME-Version: 1.0 Message-Id: <20100720081029.B414429EF6@ochil.suse.de> From: hare@suse.de (Hannes Reinecke) X-RedHat-Spam-Score: -5.01 (RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-Scanned-By: MIMEDefang 2.67 on 10.5.110.12 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH] libmultipath: simplify dm_get_name() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 20 Jul 2010 08:14:04 +0000 (UTC) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 333659b..fb69ee8 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -777,35 +777,49 @@ out: return r; } -extern int -dm_get_name(char *uuid, char *name) +extern char * +dm_get_name(char *uuid) { - vector vec; - struct multipath *mpp; - int i, rc = 0; - - vec = vector_alloc(); + struct dm_task *dmt; + struct dm_info info; + char *prefixed_uuid, *name = NULL; + const char *nametmp; - if (!vec) - return 0; + dmt = dm_task_create(DM_DEVICE_INFO); + if (!dmt) + return NULL; - if (dm_get_maps(vec)) { - goto out; + prefixed_uuid = MALLOC(UUID_PREFIX_LEN + strlen(uuid) + 1); + if (!prefixed_uuid) { + condlog(0, "cannot create prefixed uuid : %s\n", + strerror(errno)); + goto freeout; } + sprintf(prefixed_uuid, UUID_PREFIX "%s", uuid); + if (!dm_task_set_uuid(dmt, prefixed_uuid)) + goto freeout; - vector_foreach_slot(vec, mpp, i) { - if (!strcmp(uuid, mpp->wwid)) { - strcpy(name, mpp->alias); - rc=1; - break; - } - } -out: - vector_foreach_slot(vec, mpp, i) { - free_multipath(mpp, KEEP_PATHS); + if (!dm_task_run(dmt)) + goto freeout; + + if (!dm_task_get_info(dmt, &info) || !info.exists) + goto freeout; + + nametmp = dm_task_get_name(dmt); + if (nametmp && strlen(nametmp)) { + name = MALLOC(strlen(nametmp) + 1); + if (name) + strcpy(name, nametmp); + } else { + condlog(2, "%s: no device-mapper name found", uuid); } - vector_free(vec); - return rc; + +freeout: + if (prefixed_uuid) + FREE(prefixed_uuid); + dm_task_destroy(dmt); + + return name; } int diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index f3ffeaa..6c22bf3 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -37,6 +37,6 @@ int dm_remove_partmaps (const char * mapname, int need_sync); int dm_get_uuid(char *name, char *uuid); int dm_get_info (char * mapname, struct dm_info ** dmi); int dm_rename (char * old, char * new); -int dm_get_name(char * uuid, char * name); +char * dm_get_name(char * uuid); #endif /* _DEVMAPPER_H */ diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c index 3074ce1..9944675 100644 --- a/libmultipath/propsel.c +++ b/libmultipath/propsel.c @@ -247,15 +247,8 @@ select_alias (struct multipath * mp) mp->alias = get_user_friendly_alias(mp->wwid, conf->bindings_file, mp->alias_prefix); } - if (mp->alias == NULL){ - char *alias; - if ((alias = MALLOC(WWID_SIZE)) != NULL){ - if (dm_get_name(mp->wwid, alias) == 1) - mp->alias = alias; - else - FREE(alias); - } - } + if (mp->alias == NULL) + mp->alias = dm_get_name(mp->wwid); if (mp->alias == NULL) mp->alias = STRDUP(mp->wwid); } diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index 51c41e8..c526a70 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -337,15 +337,11 @@ retry: if (update_multipath_strings(mpp, vecs->pathvec)) { char *new_alias; - new_alias = MALLOC(WWID_SIZE); - if (!new_alias) { - condlog(0, "%s: failed to allocate alias", mpp->alias); - goto out; - } /* * detect an external rename of the multipath device */ - if (dm_get_name(mpp->wwid, new_alias)) { + new_alias = dm_get_name(mpp->wwid); + if (new_alias) { condlog(3, "%s multipath mapped device name has " "changed from %s to %s", mpp->wwid, mpp->alias, new_alias);