block: clean up cmdfilter sysfs interface
This patch changes the interface of the cmd filter to use a +/- notation like: echo -- +0x02 +0x03 -0x08 If neither + or - is given it defaults to + (allow command). Note: The interface was added in 2.6.17-rc1 and is unused and undocumented so far so it's safe to change it. Reviewed-by: Matthew Wilcox <willy@linux.intel.com> Reviewed-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: jens.axboe@oracle.com Cc: James.Bottomley@hansenpartnership.com Cc: dan.j.williams@intel.com Cc: pjones@redhat.com Cc: viro@zeniv.linux.org.uk Cc: dougg@torque.net Signed-off-by: Adel Gadllah <adel.gadllah@gmail.com> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
This commit is contained in:
parent
4beab5c623
commit
a4a778971b
1 changed files with 31 additions and 25 deletions
|
@ -20,7 +20,6 @@
|
||||||
#include <linux/list.h>
|
#include <linux/list.h>
|
||||||
#include <linux/genhd.h>
|
#include <linux/genhd.h>
|
||||||
#include <linux/spinlock.h>
|
#include <linux/spinlock.h>
|
||||||
#include <linux/parser.h>
|
|
||||||
#include <linux/capability.h>
|
#include <linux/capability.h>
|
||||||
#include <linux/bitops.h>
|
#include <linux/bitops.h>
|
||||||
|
|
||||||
|
@ -65,8 +64,7 @@ static ssize_t rcf_cmds_show(struct blk_cmd_filter *filter, char *page,
|
||||||
|
|
||||||
for (i = 0; i < BLK_SCSI_MAX_CMDS; i++) {
|
for (i = 0; i < BLK_SCSI_MAX_CMDS; i++) {
|
||||||
if (test_bit(i, okbits)) {
|
if (test_bit(i, okbits)) {
|
||||||
sprintf(npage, "%02x", i);
|
npage += sprintf(npage, "0x%02x", i);
|
||||||
npage += 2;
|
|
||||||
if (i < BLK_SCSI_MAX_CMDS - 1)
|
if (i < BLK_SCSI_MAX_CMDS - 1)
|
||||||
sprintf(npage++, " ");
|
sprintf(npage++, " ");
|
||||||
}
|
}
|
||||||
|
@ -92,33 +90,41 @@ static ssize_t rcf_writecmds_show(struct blk_cmd_filter *filter,
|
||||||
static ssize_t rcf_cmds_store(struct blk_cmd_filter *filter,
|
static ssize_t rcf_cmds_store(struct blk_cmd_filter *filter,
|
||||||
const char *page, size_t count, int rw)
|
const char *page, size_t count, int rw)
|
||||||
{
|
{
|
||||||
ssize_t ret = 0;
|
|
||||||
unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits;
|
unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits;
|
||||||
int cmd, status, len;
|
int cmd, set;
|
||||||
substring_t ss;
|
char *p, *status;
|
||||||
|
|
||||||
memset(&okbits, 0, sizeof(okbits));
|
if (rw == READ) {
|
||||||
|
memcpy(&okbits, filter->read_ok, sizeof(okbits));
|
||||||
for (len = strlen(page); len > 0; len -= 3) {
|
target_okbits = filter->read_ok;
|
||||||
if (len < 2)
|
} else {
|
||||||
break;
|
memcpy(&okbits, filter->write_ok, sizeof(okbits));
|
||||||
ss.from = (char *) page + ret;
|
target_okbits = filter->write_ok;
|
||||||
ss.to = (char *) page + ret + 2;
|
|
||||||
ret += 3;
|
|
||||||
status = match_hex(&ss, &cmd);
|
|
||||||
/* either of these cases means invalid input, so do nothing. */
|
|
||||||
if (status || cmd >= BLK_SCSI_MAX_CMDS)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
__set_bit(cmd, okbits);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rw == READ)
|
while ((p = strsep((char **)&page, " ")) != NULL) {
|
||||||
target_okbits = filter->read_ok;
|
set = 1;
|
||||||
else
|
|
||||||
target_okbits = filter->write_ok;
|
|
||||||
|
|
||||||
memmove(target_okbits, okbits, sizeof(okbits));
|
if (p[0] == '+') {
|
||||||
|
p++;
|
||||||
|
} else if (p[0] == '-') {
|
||||||
|
set = 0;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = simple_strtol(p, &status, 16);
|
||||||
|
|
||||||
|
/* either of these cases means invalid input, so do nothing. */
|
||||||
|
if ((status == p) || cmd >= BLK_SCSI_MAX_CMDS)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (set)
|
||||||
|
__set_bit(cmd, okbits);
|
||||||
|
else
|
||||||
|
__clear_bit(cmd, okbits);
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(target_okbits, okbits, sizeof(okbits));
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue