From patchwork Thu Jan 10 20:06:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 1961861 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by patchwork2.kernel.org (Postfix) with ESMTP id 7982EDF264 for ; Thu, 10 Jan 2013 20:09:48 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r0AK6XYp011876; Thu, 10 Jan 2013 15:06:38 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r0AK6L8s019505 for ; Thu, 10 Jan 2013 15:06:21 -0500 Received: from ether.msp.redhat.com (ether.msp.redhat.com [10.15.80.119]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r0AK6KOE019100 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 10 Jan 2013 15:06:21 -0500 Received: from ether.msp.redhat.com (localhost.localdomain [127.0.0.1]) by ether.msp.redhat.com (8.14.1/8.14.1) with ESMTP id r0AK6J3F026976; Thu, 10 Jan 2013 14:06:20 -0600 Received: (from bmarzins@localhost) by ether.msp.redhat.com (8.14.1/8.14.1/Submit) id r0AK6J61026975; Thu, 10 Jan 2013 14:06:19 -0600 Date: Thu, 10 Jan 2013 14:06:19 -0600 From: Benjamin Marzinski To: device-mapper development Message-ID: <20130110200619.GP19059@ether.msp.redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.17 (2007-11-01) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-loop: dm-devel@redhat.com Cc: Christophe Varoqui Subject: [dm-devel] [PATCH v2] multipath: make devt2devname use lstat to check sysfs links 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 dm_reassign wasn't working correctly for me because devt2devname used stat() to check if /sys/dev/block/major:minor was a symlink. But stat() never returns a symlink, if follows it. It needs to use lstat() instead. Also, I made multipath log a message when a dm device gets reassigned to use multipath. Signed-off-by: Benjamin Marzinski Acked-by: Hannes Reinecke --- libmultipath/devmapper.c | 4 +++- libmultipath/sysfs.c | 6 ++++-- libmultipath/util.c | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel Index: multipath-tools-130109/libmultipath/devmapper.c =================================================================== --- multipath-tools-130109.orig/libmultipath/devmapper.c +++ multipath-tools-130109/libmultipath/devmapper.c @@ -1394,8 +1394,10 @@ int dm_reassign(const char *mapname) return 1; } - if (!(dmt = dm_task_create(DM_DEVICE_DEPS))) + if (!(dmt = dm_task_create(DM_DEVICE_DEPS))) { + condlog(3, "%s: couldn't make dm task", mapname); return 0; + } if (!dm_task_set_name(dmt, mapname)) goto out; Index: multipath-tools-130109/libmultipath/sysfs.c =================================================================== --- multipath-tools-130109.orig/libmultipath/sysfs.c +++ multipath-tools-130109/libmultipath/sysfs.c @@ -125,8 +125,10 @@ int sysfs_check_holders(char * check_dev return 0; } - if (devt2devname(check_dev, PATH_SIZE, check_devt)) + if (devt2devname(check_dev, PATH_SIZE, check_devt)) { + condlog(1, "can't get devname for %s", check_devt); return 0; + } condlog(3, "%s: checking holder", check_dev); @@ -153,7 +155,7 @@ int sysfs_check_holders(char * check_dev } table_name = dm_mapname(major, table_minor); - condlog(3, "%s: reassign table %s old %s new %s", check_dev, + condlog(0, "%s: reassign table %s old %s new %s", check_dev, table_name, check_devt, new_devt); dm_reassign_table(table_name, check_devt, new_devt); Index: multipath-tools-130109/libmultipath/util.c =================================================================== --- multipath-tools-130109.orig/libmultipath/util.c +++ multipath-tools-130109/libmultipath/util.c @@ -161,6 +161,7 @@ devt2devname (char *devname, int devname struct stat statbuf; memset(block_path, 0, sizeof(block_path)); + memset(dev, 0, sizeof(dev)); if (sscanf(devt, "%u:%u", &major, &minor) != 2) { condlog(0, "Invalid device number %s", devt); return 1; @@ -172,7 +173,7 @@ devt2devname (char *devname, int devname if (stat("/sys/dev/block", &statbuf) == 0) { /* Newer kernels have /sys/dev/block */ sprintf(block_path,"/sys/dev/block/%u:%u", major, minor); - if (stat(block_path, &statbuf) == 0) { + if (lstat(block_path, &statbuf) == 0) { if (S_ISLNK(statbuf.st_mode) && readlink(block_path, dev, FILE_NAME_SIZE) > 0) { char *p = strrchr(dev, '/');