From: Richard Purdie <rpurdie@openedhand.com>
To: Nick Piggin <nickpiggin@yahoo.com.au>,
Hugh Dickins <hugh@veritas.com>,
kernel list <linux-kernel@vger.kernel.org>,
linux-mtd@lists.infradead.org, dwmw2@infradead.org
Subject: [PATCH 6/9] mtd: Add a 'block unused' ioctl call to provide hints to block drivers
Date: Fri, 02 Mar 2007 15:54:54 +0000 [thread overview]
Message-ID: <1172850894.11149.126.camel@localhost.localdomain> (raw)
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.
Signed-off-by: Richard Purdie <rpurdie@openedhand.com>
---
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(-)
Index: linux/include/linux/fs.h
===================================================================
--- linux.orig/include/linux/fs.h 2007-02-28 18:16:52.000000000 +0000
+++ linux/include/linux/fs.h 2007-03-02 14:46:34.000000000 +0000
@@ -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 */
Index: linux/include/linux/swap.h
===================================================================
--- linux.orig/include/linux/swap.h 2007-03-02 14:35:02.000000000 +0000
+++ linux/include/linux/swap.h 2007-03-02 14:46:34.000000000 +0000
@@ -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 */
};
Index: linux/mm/swapfile.c
===================================================================
--- linux.orig/mm/swapfile.c 2007-03-02 14:35:04.000000000 +0000
+++ linux/mm/swapfile.c 2007-03-02 14:46:34.000000000 +0000
@@ -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;
Index: linux/block/ioctl.c
===================================================================
--- linux.orig/block/ioctl.c 2007-02-28 18:16:52.000000000 +0000
+++ linux/block/ioctl.c 2007-03-02 14:46:34.000000000 +0000
@@ -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();
next reply other threads:[~2007-03-02 15:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-02 15:54 Richard Purdie [this message]
2007-03-05 21:38 ` [PATCH 6/9] mtd: Add a 'block unused' ioctl call to provide hints to block drivers Pavel Machek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1172850894.11149.126.camel@localhost.localdomain \
--to=rpurdie@openedhand.com \
--cc=dwmw2@infradead.org \
--cc=hugh@veritas.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=nickpiggin@yahoo.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox