Skip to contentSkip to conversation

swsusp: fix breakage with swap on LVM

PATCH Rafael J. Wysocki 2 participants 4 messages Feb 16, 2006 – Feb 18, 2006 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 2 lines · Pavel Machek

-rc3 version looks ok, and we probably want it in asap. -mm version looks a bit long... --p

That's because it adds a new function + comment.

I think it's not a good idea to remake mm/swapfile.c:swap_type_of() in a -rc3-like fashion, because it is called by the userland interface for a different purpose and should not return non-error for the argument being zero.

Greetings,
Rafael

#2 lore raw
Quoted 10 lines · Rafael J. Wysocki
Quoted 2 lines · Pavel Machek

-rc3 version looks ok, and we probably want it in asap. -mm version looks a bit long... --p

That's because it adds a new function + comment.

I think it's not a good idea to remake mm/swapfile.c:swap_type_of() in a -rc3-like fashion, because it is called by the userland interface for a different purpose and should not return non-error for the argument being zero.

Well, alternatively I can change the userland interface. :-)

---
 kernel/power/user.c |   13 +++++++++----
 mm/swapfile.c       |    6 ++++--
 2 files changed, 13 insertions(+), 6 deletions(-)
mm/swapfile.c +4 -2
Index: linux-2.6.16-rc3-mm1/mm/swapfile.c
===================================================================
@@ -428,14 +428,16 @@ int swap_type_of(dev_t device)
 {
 	int i;
 
-	if (!device)
-		return -EINVAL;
 	spin_lock(&swap_lock);
 	for (i = 0; i < nr_swapfiles; i++) {
 		struct inode *inode;
 
 		if (!(swap_info[i].flags & SWP_WRITEOK))
 			continue;
+		if (!device) {
+			spin_unlock(&swap_lock);
+			return i;
+		}
 		inode = swap_info->swap_file->f_dentry->d_inode;
 		if (S_ISBLK(inode->i_mode) &&
 		    device == MKDEV(imajor(inode), iminor(inode))) {
kernel/power/user.c +9 -4
Index: linux-2.6.16-rc3-mm1/kernel/power/user.c
===================================================================
@@ -51,7 +51,7 @@ static int snapshot_open(struct inode *i
 	filp->private_data = data;
 	memset(&data->handle, 0, sizeof(struct snapshot_handle));
 	if ((filp->f_flags & O_ACCMODE) == O_RDONLY) {
-		data->swap = swap_type_of(swsusp_resume_device);
+		data->swap = swsusp_resume_device ? swap_type_of(swsusp_resume_device) : -1;
 		data->mode = O_RDONLY;
 	} else {
 		data->swap = -1;
@@ -252,9 +252,14 @@ static int snapshot_ioctl(struct inode *
 			 * User space encodes device types as two-byte values,
 			 * so we need to recode them
 			 */
-			data->swap = swap_type_of(old_decode_dev(arg));
-			if (data->swap < 0)
-				error = -ENODEV;
+			if (old_decode_dev(arg)) {
+				data->swap = swap_type_of(old_decode_dev(arg));
+				if (data->swap < 0)
+					error = -ENODEV;
+			} else {
+				data->swap = -1;
+				error = -EINVAL;
+			}
 		} else {
 			error = -EPERM;
 		}
#3 lore raw
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines · Pavel Machek

-rc3 version looks ok, and we probably want it in asap. -mm version looks a bit long... --p

Quoted 8 lines
Quoted 6 lines

That's because it adds a new function + comment.

I think it's not a good idea to remake mm/swapfile.c:swap_type_of() in a -rc3-like fashion, because it is called by the userland interface for a different purpose and should not return non-error for the argument being zero.

Well, alternatively I can change the userland interface. :-)

ACK.

Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms         
author Acked-by Pavel Machek
#4 lore raw
Quoted 8 lines · Pavel Machek
Quoted 7 lines · Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki
Quoted 2 lines · Pavel Machek

-rc3 version looks ok, and we probably want it in asap. -mm version looks a bit long... --p

That's because it adds a new function + comment.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

I think it's not a good idea to remake mm/swapfile.c:swap_type_of() in a -rc3-like fashion, because it is called by the userland interface for a different purpose and should not return non-error for the argument being zero.

Well, alternatively I can change the userland interface. :-)

ACK.

OK

Andrew, could you replace the swsusp-separate-swap-writing-reading-code-rev-2-fix-breakage-with-swap-on-lvm.patch with this one, please? [Appended once again for convenience.]

Rafael
---

Restore the compatibility with the older code and make it possible to suspend if the kernel command line doesn't contain the "resume=" argument.

---
 kernel/power/user.c |   13 +++++++++----
 mm/swapfile.c       |    6 ++++--
 2 files changed, 13 insertions(+), 6 deletions(-)
mm/swapfile.c +4 -2
Index: linux-2.6.16-rc3-mm1/mm/swapfile.c
===================================================================
@@ -428,14 +428,16 @@ int swap_type_of(dev_t device)
 {
 	int i;
 
-	if (!device)
-		return -EINVAL;
 	spin_lock(&swap_lock);
 	for (i = 0; i < nr_swapfiles; i++) {
 		struct inode *inode;
 
 		if (!(swap_info[i].flags & SWP_WRITEOK))
 			continue;
+		if (!device) {
+			spin_unlock(&swap_lock);
+			return i;
+		}
 		inode = swap_info->swap_file->f_dentry->d_inode;
 		if (S_ISBLK(inode->i_mode) &&
 		    device == MKDEV(imajor(inode), iminor(inode))) {
kernel/power/user.c +9 -4
Index: linux-2.6.16-rc3-mm1/kernel/power/user.c
===================================================================
@@ -51,7 +51,7 @@ static int snapshot_open(struct inode *i
 	filp->private_data = data;
 	memset(&data->handle, 0, sizeof(struct snapshot_handle));
 	if ((filp->f_flags & O_ACCMODE) == O_RDONLY) {
-		data->swap = swap_type_of(swsusp_resume_device);
+		data->swap = swsusp_resume_device ? swap_type_of(swsusp_resume_device) : -1;
 		data->mode = O_RDONLY;
 	} else {
 		data->swap = -1;
@@ -252,9 +252,14 @@ static int snapshot_ioctl(struct inode *
 			 * User space encodes device types as two-byte values,
 			 * so we need to recode them
 			 */
-			data->swap = swap_type_of(old_decode_dev(arg));
-			if (data->swap < 0)
-				error = -ENODEV;
+			if (old_decode_dev(arg)) {
+				data->swap = swap_type_of(old_decode_dev(arg));
+				if (data->swap < 0)
+					error = -ENODEV;
+			} else {
+				data->swap = -1;
+				error = -EINVAL;
+			}
 		} else {
 			error = -EPERM;
 		}