Package: parted / 3.2-7

hurd-reread.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
From 6ea0e57f5adb906b27af877c2533bb41c64dc3db Mon Sep 17 00:00:00 2001
From: Colin Watson <cjwatson@ubuntu.com>
Date: Fri, 28 Mar 2014 17:09:54 +0000
Subject: Implement partition table rereading on GNU/Hurd

Patch-Name: hurd-reread.patch
---
 libparted/arch/gnu.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 78 insertions(+), 6 deletions(-)

diff --git a/libparted/arch/gnu.c b/libparted/arch/gnu.c
index 5a1c73e..ba384fb 100644
--- a/libparted/arch/gnu.c
+++ b/libparted/arch/gnu.c
@@ -185,7 +185,7 @@ _init_device (const char *path)
 	if (!dev->arch_specific)
 		goto error_free_path;
 
-	dev->type = PED_DEVICE_FILE;	/* FIXME? */
+	dev->type = PED_DEVICE_UNKNOWN;	/* It's deprecated anyway */
 	dev->open_count = 0;
 	dev->read_only = 0;
 	dev->external_mode = 0;
@@ -204,11 +204,83 @@ error:
 	return NULL;
 }
 
+/* Ask the kernel and translators to reload the partition table.
+   XXX: Will probably be replaced by some RPC to partfs when it's finished.  In
+   the meantime, gnumach's glue layer will pass BLKRRPART to the Linux drivers.
+   */
+#define BLKRRPART 0x125F
 static int
-_kernel_reread_part_table (PedDevice* dev)
+_reread_part_table (PedDevice* dev)
 {
-	/* XXX: We must wait for partfs to be finished.  */
-	return 1;
+	struct store *store = GNU_SPECIFIC (dev)->store;
+	int retry_count = 9;
+	int len = strlen (dev->path);
+	char path[len + 3 + 1];
+	int i;
+	int done = 1;
+
+	sync ();
+
+	if(strcmp (store->class->name, "device") == 0) {
+		while (device_set_status (store->port, BLKRRPART, NULL, 0)) {
+			retry_count--;
+			sync ();
+			if (retry_count == 3)
+				sleep (1); /* Pause to allow system to settle */
+
+			if (!retry_count) {
+				ped_exception_throw (
+					PED_EXCEPTION_WARNING,
+					PED_EXCEPTION_IGNORE,
+				_("WARNING: the kernel failed to re-read the "
+				  "partition table on %s (%s).  As a result, "
+				  "it may not reflect all of your changes "
+				  "until after reboot."),
+					dev->path, strerror (errno));
+				return 0;
+			}
+		}
+	}
+
+	i = 1;
+	while (1) {
+		file_t node;
+		error_t err;
+
+		/* Throw away all active parted-based translators */
+		snprintf (path, sizeof (path), "%ss%u", dev->path, i);
+		node = file_name_lookup (path, O_NOTRANS, 0666);
+		if (node == MACH_PORT_NULL) {
+			if (errno == ENOENT)
+				/* Finished looping over them */
+				break;
+
+			ped_exception_throw (
+				PED_EXCEPTION_WARNING,
+				PED_EXCEPTION_IGNORE,
+				_("Warning: unable to open %s (%s). As a "
+				  "result, it may not reflect all of your "
+				  "changes until after reboot."),
+					path, strerror (errno));
+			done = 0;
+		}
+
+		err = file_set_translator (node, 0, FS_TRANS_SET,
+			0, 0, 0, MACH_PORT_NULL, MACH_MSG_TYPE_COPY_SEND);
+		if (err) {
+			ped_exception_throw (
+				PED_EXCEPTION_WARNING,
+				PED_EXCEPTION_IGNORE,
+				_("Warning: failed to make translator go away "
+				  "on %s (%s). As a result, it may not reflect "
+				  "all of your changes until after reboot."),
+					dev->path, strerror (errno));
+			done = 0;
+		}
+		i++;
+	}
+
+	return done;
 }
 
 /* Free the memory associated with a PedDevice structure.  */
@@ -355,7 +427,7 @@ gnu_close (PedDevice* dev)
 	_flush_cache (dev);
 
 	if (dev->dirty && dev->type != PED_DEVICE_FILE) {
-		if (_kernel_reread_part_table (dev))
+		if (_reread_part_table (dev))
 			dev->dirty = 0;
 	}
 
@@ -858,7 +930,7 @@ gnu_partition_is_busy (const PedPartition* part)
 static int
 gnu_disk_commit (PedDisk* disk)
 {
-	return 1;
+	return _reread_part_table (disk->dev);
 }
 
 static PedDeviceArchOps gnu_dev_ops = {