Skip to contentSkip to conversation

mtd: Add a 'block unused' ioctl call to provide hints to block drivers

PATCH NAK Richard Purdie 2 participants 2 messages Mar 2, 2007 – Mar 5, 2007

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 6/9 mtd: Add a 'block unused' ioctl call to provide hints to block drivers

Knowing that the data in a given block is now unused is a useful feature that some block drivers can take advantage of, especially when dealing with devices like flash.

This adds an ioctl which allows such hints to be passed to the block driver. Its shouldn't provide false positives but doesn't have to provide the signal in all cases - its intended as a hint.

Support for the ioctl is added to the swap subsystem when the swap header indicates such notification would be useful though an added flags bitfield. The swaponflash driver takes advantage of this functionality.

---
 block/ioctl.c        |    4 ++++
 include/linux/fs.h   |    1 +
 include/linux/swap.h |    5 ++++-
 mm/swapfile.c        |    7 ++++++-
 4 files changed, 15 insertions(+), 2 deletions(-)
include/linux/fs.h +1 -0
Index: linux/include/linux/fs.h
===================================================================
@@ -214,6 +214,7 @@ extern int dir_notify_enable;
 #define BLKTRACESTART _IO(0x12,116)
 #define BLKTRACESTOP _IO(0x12,117)
 #define BLKTRACETEARDOWN _IO(0x12,118)
+#define BLKSWAPMARKUNUSED _IOW(0x12, 1197, int)
 
 #define BMAP_IOCTL 1		/* obsolete - kept for compatibility */
 #define FIBMAP	   _IO(0x00,1)	/* bmap access */
include/linux/swap.h +4 -1
Index: linux/include/linux/swap.h
===================================================================
@@ -65,7 +65,9 @@ union swap_header {
 		__u32		nr_badpages;
 		unsigned char	sws_uuid[16];
 		unsigned char	sws_volume[16];
-		__u32		padding[117];
+		__u32		flags;
+#define SWAPFLAG_UNUSED_IOCTL (1 << 0)
+		__u32		padding[113];
 		__u32		badpages[1];
 	} info;
 };
@@ -119,6 +121,7 @@ enum {
 	SWP_USED	= (1 << 0),	/* is slot in swap_info[] used? */
 	SWP_WRITEOK	= (1 << 1),	/* ok to write to this swap?	*/
 	SWP_ACTIVE	= (SWP_USED | SWP_WRITEOK),
+	SWP_UNUSED_IOCTL = (1 << 2),
 					/* add others here before... */
 	SWP_SCANNING	= (1 << 8),	/* refcount in scan_swap_map */
 };
mm/swapfile.c +6 -1
Index: linux/mm/swapfile.c
===================================================================
@@ -284,6 +284,8 @@ static int swap_entry_free(struct swap_i
 				swap_list.next = p - swap_info;
 			nr_swap_pages++;
 			p->inuse_pages--;
+			if (p->flags & SWP_UNUSED_IOCTL)
+				blkdev_ioctl(p->swap_file->f_mapping->host, p->swap_file, BLKSWAPMARKUNUSED, offset);
 		}
 	}
 	return count;
@@ -1649,6 +1651,9 @@ asmlinkage long sys_swapon(const char __
 			goto bad_swap;
 		}
 
+		if (swap_header->info.flags & SWAPFLAG_UNUSED_IOCTL)
+			p->flags |= SWP_UNUSED_IOCTL;
+
 		error = 0;
 		memset(p->swap_map, 0, maxpages * sizeof(short));
 		for (i = 0; i < swap_header->info.nr_badpages; i++) {
@@ -1684,7 +1689,7 @@ asmlinkage long sys_swapon(const char __
 
 	mutex_lock(&swapon_mutex);
 	spin_lock(&swap_lock);
-	p->flags = SWP_ACTIVE;
+	p->flags |= SWP_ACTIVE;
 	nr_swap_pages += nr_good_pages;
 	total_swap_pages += nr_good_pages;
 
block/ioctl.c +4 -0
Index: linux/block/ioctl.c
===================================================================
@@ -274,6 +274,10 @@ int blkdev_ioctl(struct inode *inode, st
 			return -EFAULT;
 		return 0;
 	}
+	case BLKSWAPMARKUNUSED:
+		if (!capable(CAP_SYS_ADMIN))
+			return -EACCES;
+		return blkdev_driver_ioctl(inode, file, disk, cmd, arg);
 	}
 
 	lock_kernel();
#1 lore raw

Hi!

Quoted 5 lines

Knowing that the data in a given block is now unused is a useful feature that some block drivers can take advantage of, especially when dealing with devices like flash.

This adds an ioctl which allows such hints to be passed to the

Maybe Documentation/ piece would be nice if this can be called from userspace....

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html