[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

rpms/parted/devel parted-1.6.25-dm.patch, NONE, 1.1 parted.spec, 1.54, 1.55



Author: pjones

Update of /cvs/dist/rpms/parted/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv9397

Modified Files:
	parted.spec 
Added Files:
	parted-1.6.25-dm.patch 
Log Message:
- add support for putting partitions on device-mapper devices


parted-1.6.25-dm.patch:
 configure.in            |   12 +
 include/parted/device.h |    3 
 libparted/Makefile.am   |    1 
 libparted/linux.c       |  335 +++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 348 insertions(+), 3 deletions(-)

--- NEW FILE parted-1.6.25-dm.patch ---
--- parted-1.6.25/include/parted/device.h.dm	2005-11-15 17:51:59.000000000 -0500
+++ parted-1.6.25/include/parted/device.h	2005-11-15 17:51:59.000000000 -0500
@@ -36,7 +36,8 @@
 	PED_DEVICE_UBD		= 8,
 	PED_DEVICE_DASD		= 9,
 	PED_DEVICE_VIODASD	= 10,
-	PED_DEVICE_SX8		= 11
+	PED_DEVICE_SX8		= 11,
+	PED_DEVICE_DM	   = 12,
 } PedDeviceType;
 
 typedef struct _PedDevice PedDevice;
--- parted-1.6.25/configure.in.dm	2005-11-02 07:27:40.000000000 -0500
+++ parted-1.6.25/configure.in	2005-11-15 17:51:59.000000000 -0500
@@ -242,6 +242,16 @@
 )
 AC_SUBST(UUID_LIBS)
 
+dnl Check for libdevmapper
+DM_LIBS=""
+AC_CHECK_LIB(devmapper, dm_task_create, DM_LIBS="-ldevmapper -lselinux -lsepol",
+	AC_MSG_ERROR(
+GNU Parted requires libdevmapper - a part of the device-mapper package.
+	)
+	exit
+)
+AC_SUBST(DM_LIBS)
+
 dnl Check for libreiserfs
 REISER_LIBS=""
 if test "$enable_dynamic_loading" = no -a "$enable_discover_only" = no; then
@@ -335,7 +345,7 @@
 systems.  It is a standard part of a GNU/Hurd system.
 		)
 		exit,
-		$OS_LIBS $UUID_LIBS $LIBS
+		$OS_LIBS $UUID_LIBS $DM_LIBS $LIBS
 	)
 	LIBS="$OLD_LIBS"
 fi
--- parted-1.6.25/libparted/linux.c.dm	2005-11-15 17:51:59.000000000 -0500
+++ parted-1.6.25/libparted/linux.c	2005-11-15 19:35:54.000000000 -0500
@@ -17,6 +17,7 @@
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */
 
+#define _GNU_SOURCE 1
 #include "config.h"
 
 #include <parted/parted.h>
@@ -37,6 +38,7 @@
 #include <sys/types.h>
 #include <sys/utsname.h>	/* for uname() */
 #include <scsi/scsi.h>
+#include <libdevmapper.h>
 
 #include "blkpg.h"
 
@@ -270,6 +272,96 @@
 }
 
 static int
+readFD (int fd, char **buf)
+{
+    char *p;
+    size_t size = 16384;
+    int s, filesize;
+
+    *buf = calloc (16384, sizeof (char));
+    if (*buf == 0) {
+	return -1;
+    }
+
+    filesize = 0;
+    do {
+	p = &(*buf) [filesize];
+	s = read (fd, p, 16384);
+	if (s < 0)
+	    break;
+	filesize += s;
+	/* only exit for empty reads */
+	if (s == 0)
+	    break;
+	size += s;
+	*buf = realloc (*buf, size);
+    } while (1);
+
+    if (filesize == 0 && s < 0) {
+	free (*buf);
+	*buf = NULL;
+	return -1;
+    }
+
+    return filesize;
+}
+
+static int
+_is_dm_major (int major)
+{
+	int	fd;
+	char*	buf = NULL;
+	char*	line;
+	char*	end;
+	int	bd = 0;
+        int	rc = 0;
+	char	c;
+
+	fd = open ("/proc/devices", O_RDONLY);
+	if (fd < 0)
+		return 0;
+
+	if (readFD(fd, &buf) < 0)
+		return 0; 
+	line = buf;
+	end = strchr(line, '\n');
+	while (end && *end) {
+		char *name;
+		int maj;
+
+		c = *end;
+		*end = '\0';
+
+		if (!bd) {
+			if (!strncmp(line, "Block devices:", 14))
+				bd = 1;
+			goto next;
+		}
+
+		name = strrchr(line, ' ');
+		if (!name || !*name || strcmp(name+1, "device-mapper"))
+			goto next;
+
+		maj = strtol(line, &name, 10);
+		if (maj == major) {
+			free(buf);
+			return 1;
+		}
+
+next:
+		*end = c;
+		line = strchr(end+1, '\n');
+		if (line && *line) {
+			line++;
+			end = strchr(line, '\n');
+		} else
+			end = line;
+	}
+	free(buf);
+	return 0;
+}
+
+static int
 _device_stat (PedDevice* dev, struct stat * dev_stat)
 {
 	PED_ASSERT (dev != NULL, return 0);
@@ -330,6 +422,8 @@
 		dev->type = PED_DEVICE_CPQARRAY;
 	} else if (dev_major == UBD_MAJOR && (dev_minor % 0x10 == 0)) {
 		dev->type = PED_DEVICE_UBD;
+	} else if (_is_dm_major(dev_major)) {
+		dev->type = PED_DEVICE_DM;
 	} else {
 		dev->type = PED_DEVICE_UNKNOWN;
 	}
@@ -973,6 +1067,11 @@
 			goto error_free_arch_specific;
 		break;
 
+	case PED_DEVICE_DM:
+		if (!init_generic (dev, _("Linux device-mapper")))
+			goto error_free_arch_specific;
+		break;
+
 	case PED_DEVICE_UNKNOWN:
 		if (!init_generic (dev, _("Unknown")))
 			goto error_free_arch_specific;
@@ -1836,6 +1935,238 @@
 }
 
 static int
+_dm_remove_map(int major, int minor)
+{
+	struct dm_task	  *task = NULL;
+	int		     rc;
+
+	task = dm_task_create(DM_DEVICE_REMOVE);
+	if (!task)
+		return 1;
+
+	dm_task_set_major (task, major);
+	dm_task_set_minor (task, minor);
+
+	rc = dm_task_run(task);
+	dm_task_destroy(task);
+	if (rc < 0)
+		return 1;
+
+	return 0;
+}
+
+static int
+_dm_remove_map_name(char *name)
+{
+	struct dm_task	  *task = NULL;
+	int		     rc;
+
+	task = dm_task_create(DM_DEVICE_REMOVE);
+	if (!task)
+		return 1;
+
+	dm_task_set_name (task, name);
+
+	rc = dm_task_run(task);
+	dm_task_destroy(task);
+	if (rc < 0)
+		return 1;
+
+	return 0;
+}
+
+static int 
+_dm_is_part (struct dm_info *this, char *name)
+{
+	struct dm_task*	task = NULL;
+	struct dm_info*	info = alloca(sizeof *info);
+	struct dm_deps*	deps = NULL;
+	int		rc = 0;
+	unsigned int	i;
+
+	task = dm_task_create(DM_DEVICE_DEPS);
+	if (!task)
+		return 0;
+	
+	dm_task_set_name(task, name);
+	rc = dm_task_run(task);
+	if (rc < 0) {
+		rc = 0;
+		goto err;
+	}
+        rc = 0;
+
+	memset(info, '\0', sizeof *info);
+	dm_task_get_info(task, info);
+	if (!info->exists)
+		goto err;
+
+	deps = dm_task_get_deps(task);
+	if (!deps)
+		goto err;
+
+        rc = 0;
+	for (i = 0; i < deps->count; i++) {
+                unsigned int ma = major(deps->device[i]),
+			     mi = minor(deps->device[i]);
+
+		if (ma == this->major && mi == this->minor)
+			rc = 1;
+	}
+
+err:
+	dm_task_destroy(task);
+	return rc;
+}
+
+static int
+_dm_remove_parts (PedDevice* dev)
+{
+	struct stat		dev_stat;
+	struct dm_task*		task = NULL;
+	struct dm_info*		info = alloca(sizeof *info);
+	struct dm_names*	names = NULL;
+	unsigned int		next = 0;
+	int			i;
+	int			rc;
+
+	if (!_device_stat (dev, &dev_stat))
+		goto err;
+
+	task = dm_task_create(DM_DEVICE_LIST);
+	if (!task)
+		goto err;
+
+	dm_task_set_major (task, major (dev_stat.st_rdev));
+	dm_task_set_minor (task, minor (dev_stat.st_rdev));
+
+	rc = dm_task_run(task);
+	if (rc < 0)
+		goto err;
+
+	memset(info, '\0', sizeof *info);
+	dm_task_get_info(task, info);
+	if (!info->exists)
+		goto err;
+
+	names = dm_task_get_names(task);
+	if (!names)
+		goto err;
+
+	rc = 0;
+	do {
+		names = (void *)names + next;
+
+		if (_dm_is_part(info, names->name))
+			rc += _dm_remove_map_name(names->name);
+
+		next = names->next;
+	} while (next);
+
+	dm_task_destroy(task);
+	task = NULL;
+
+	if (!rc)
+		return 1;
+err:
+	if (task)
+		dm_task_destroy(task);
+	ped_exception_throw (PED_EXCEPTION_WARNING, PED_EXCEPTION_IGNORE,
+		_("parted was unable to re-read the partition "
+		  "table on %s (%s).  This means Linux won't know "
+		  "anything about the modifications you made. "),
+		dev->path, strerror (errno));
+	return 0;
+}
+
+static int
+_dm_add_partition (PedDisk* disk, PedPartition* part)
+{
+	struct dm_task* task;
+	struct stat	dev_stat;
+	int	     rc;
+	char*	   vol_name = NULL;
+	char*	   dev_name = NULL;
+	char*	   params = NULL;
+
+	if (ped_disk_type_check_feature (disk->type,
+					PED_DISK_TYPE_PARTITION_NAME))
+		vol_name = (char *)ped_partition_get_name (part);
+	
+	dev_name = _device_get_part_path (disk->dev, part->num);
+	if (!dev_name)
+		return 0;
+
+	if (!vol_name) {
+		vol_name = strrchr (dev_name, '/');
+		if (vol_name && *vol_name && *(++vol_name))
+			vol_name = strdup (vol_name);
+		else
+			asprintf (&vol_name, "%s%d", dev_name, part->num);
+		if (!vol_name)
+			return 0;
+	}
+
+	if (!_device_stat (disk->dev, &dev_stat))
+		goto err;
+
+	asprintf (&params, "%d:%d %lu", major (dev_stat.st_rdev),
+			minor (dev_stat.st_rdev),
+			part->geom.start);
+	if (!params)
+		goto err;
+
+	task = dm_task_create (DM_DEVICE_CREATE);
+	if (!task)
+		goto err;
+
+	dm_task_set_name (task, vol_name);
+	dm_task_add_target (task, 0, part->geom.length,
+		"linear", params);
+	rc = dm_task_run(task);
+	if (rc >= 0) {
+                //printf("0 %ld linear %s\n", part->geom.length, params);
+		dm_task_destroy(task);
+		free(params);
+		free(vol_name);
+		return 1;
+	} else {
+		_dm_remove_map_name(vol_name);
+	}
+err:
+	if (task)
+		dm_task_destroy (task);
+	if (params)
+		free (params);
+	free (vol_name);
+	return 0;
+}
+
+static int
+_dm_reread_part_table (PedDisk* disk)
+{
+	int     rc = 1;
+	int     last = PED_MAX (ped_disk_get_last_partition_num (disk), 16);
+	int     i;
+
+	sync();
+	if (!_dm_remove_parts(disk->dev))
+		rc = 0;
+
+	for (i = 1; i <= last; i++) {
+		PedPartition*	   part;
+
+		part = ped_disk_get_partition (disk, i);
+		if (!part)
+			continue;
+
+		if (!_dm_add_partition (disk, part))
+			rc = 0;
+	}
+	return rc;
+}
+
+static int
 _kernel_reread_part_table (PedDevice* dev)
 {
 	LinuxSpecific*	arch_specific = LINUX_SPECIFIC (dev);
@@ -1878,7 +2209,9 @@
 static int
 linux_disk_commit (PedDisk* disk)
 {
-	if (disk->dev->type != PED_DEVICE_FILE) {
+	if (disk->dev->type == PED_DEVICE_DM) {
+		return _dm_reread_part_table (disk);
+	} else if (disk->dev->type != PED_DEVICE_FILE) {
 		/* The ioctl() command BLKPG_ADD_PARTITION does not notify
 		 * the devfs system; consequently, /proc/partitions will not
 		 * be up to date, and the proper links in /dev are not
--- parted-1.6.25/libparted/Makefile.am.dm	2005-11-15 17:51:59.000000000 -0500
+++ parted-1.6.25/libparted/Makefile.am	2005-11-15 17:51:59.000000000 -0500
@@ -56,6 +56,7 @@
 				gnu.c
 
 libparted_la_LIBADD   = @UUID_LIBS@			\
+			@DM_LIBS@			\
 			@OS_LIBS@			\
 			@REISER_LIBS@			\
 			fs_amiga/libamigafs.la		\


Index: parted.spec
===================================================================
RCS file: /cvs/dist/rpms/parted/devel/parted.spec,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- parted.spec	9 Nov 2005 19:18:54 -0000	1.54
+++ parted.spec	16 Nov 2005 00:40:42 -0000	1.55
@@ -4,7 +4,7 @@
 Summary: The GNU disk partition manipulation program.
 Name: parted
 Version: 1.6.25
-Release: 1
+Release: 2
 Source: ftp://ftp.gnu.org/gnu/%{name}/%{name}-%{version}.tar.gz
 Patch0: parted-1.6.3-fat.c.patch
 Patch3: parted-1.6.25-sx8.patch
@@ -13,6 +13,7 @@
 Patch150: parted-1.6.25-iseries.patch
 Patch151: parted-1.6.23-aix.patch
 Patch152: parted-1.6.15-dasd_geometry.patch
+Patch153: parted-1.6.25-dm.patch
 
 Buildroot: %{_tmppath}/%{name}-root
 License: GPL
@@ -48,6 +49,7 @@
 %patch3 -p1 -b .sx8
 %patch151 -p1 -b .aix
 %patch152 -p1 -b .dasd_geometry
+%patch153 -p1 -b .dm
 
 iconv -f iso-8859-1 -t utf-8 < doc/pt_BR-parted.8 > doc/pt_BR-parted.8_
 mv doc/pt_BR-parted.8_ doc/pt_BR-parted.8
@@ -96,6 +98,9 @@
 %{_libdir}/*.a*
 
 %changelog
+* Tue Nov 15 2005 Peter Jones <pjones redhat com> 1.6.25-2
+- add support for partitions on dm devices
+
 * Wed Nov 09 2005 Chris Lumens <clumens redhat com> 1.6.25-1
 - Updated to 1.6.25.
 - Update DASD, iseries, and SX8 patches.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]