diff options
author | Adel Gadllah <adel.gadllah@gmail.com> | 2008-08-16 01:21:06 -0400 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2008-08-27 03:50:19 -0400 |
commit | a4a778971b9cfcbedb8648ba502d801f7db04c47 (patch) | |
tree | f8e66d6a6a53f0b277009763e703da1b0f9fc58b /block/cmd-filter.c | |
parent | 4beab5c623fef4622f9a8593f85760ff10b5a3f7 (diff) |
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>
Diffstat (limited to 'block/cmd-filter.c')
-rw-r--r-- | block/cmd-filter.c | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/block/cmd-filter.c b/block/cmd-filter.c index 0e3a123944a..1d4026206ac 100644 --- a/block/cmd-filter.c +++ b/block/cmd-filter.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/list.h> | 20 | #include <linux/list.h> |
21 | #include <linux/genhd.h> | 21 | #include <linux/genhd.h> |
22 | #include <linux/spinlock.h> | 22 | #include <linux/spinlock.h> |
23 | #include <linux/parser.h> | ||
24 | #include <linux/capability.h> | 23 | #include <linux/capability.h> |
25 | #include <linux/bitops.h> | 24 | #include <linux/bitops.h> |
26 | 25 | ||
@@ -65,8 +64,7 @@ static ssize_t rcf_cmds_show(struct blk_cmd_filter *filter, char *page, | |||
65 | 64 | ||
66 | for (i = 0; i < BLK_SCSI_MAX_CMDS; i++) { | 65 | for (i = 0; i < BLK_SCSI_MAX_CMDS; i++) { |
67 | if (test_bit(i, okbits)) { | 66 | if (test_bit(i, okbits)) { |
68 | sprintf(npage, "%02x", i); | 67 | npage += sprintf(npage, "0x%02x", i); |
69 | npage += 2; | ||
70 | if (i < BLK_SCSI_MAX_CMDS - 1) | 68 | if (i < BLK_SCSI_MAX_CMDS - 1) |
71 | sprintf(npage++, " "); | 69 | sprintf(npage++, " "); |
72 | } | 70 | } |
@@ -92,33 +90,41 @@ static ssize_t rcf_writecmds_show(struct blk_cmd_filter *filter, | |||
92 | static ssize_t rcf_cmds_store(struct blk_cmd_filter *filter, | 90 | static ssize_t rcf_cmds_store(struct blk_cmd_filter *filter, |
93 | const char *page, size_t count, int rw) | 91 | const char *page, size_t count, int rw) |
94 | { | 92 | { |
95 | ssize_t ret = 0; | ||
96 | unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits; | 93 | unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits; |
97 | int cmd, status, len; | 94 | int cmd, set; |
98 | substring_t ss; | 95 | char *p, *status; |
99 | 96 | ||
100 | memset(&okbits, 0, sizeof(okbits)); | 97 | if (rw == READ) { |
101 | 98 | memcpy(&okbits, filter->read_ok, sizeof(okbits)); | |
102 | for (len = strlen(page); len > 0; len -= 3) { | 99 | target_okbits = filter->read_ok; |
103 | if (len < 2) | 100 | } else { |
104 | break; | 101 | memcpy(&okbits, filter->write_ok, sizeof(okbits)); |
105 | ss.from = (char *) page + ret; | 102 | target_okbits = filter->write_ok; |
106 | ss.to = (char *) page + ret + 2; | 103 | } |
107 | ret += 3; | 104 | |
108 | status = match_hex(&ss, &cmd); | 105 | while ((p = strsep((char **)&page, " ")) != NULL) { |
106 | set = 1; | ||
107 | |||
108 | if (p[0] == '+') { | ||
109 | p++; | ||
110 | } else if (p[0] == '-') { | ||
111 | set = 0; | ||
112 | p++; | ||
113 | } | ||
114 | |||
115 | cmd = simple_strtol(p, &status, 16); | ||
116 | |||
109 | /* either of these cases means invalid input, so do nothing. */ | 117 | /* either of these cases means invalid input, so do nothing. */ |
110 | if (status || cmd >= BLK_SCSI_MAX_CMDS) | 118 | if ((status == p) || cmd >= BLK_SCSI_MAX_CMDS) |
111 | return -EINVAL; | 119 | return -EINVAL; |
112 | 120 | ||
113 | __set_bit(cmd, okbits); | 121 | if (set) |
122 | __set_bit(cmd, okbits); | ||
123 | else | ||
124 | __clear_bit(cmd, okbits); | ||
114 | } | 125 | } |
115 | 126 | ||
116 | if (rw == READ) | 127 | memcpy(target_okbits, okbits, sizeof(okbits)); |
117 | target_okbits = filter->read_ok; | ||
118 | else | ||
119 | target_okbits = filter->write_ok; | ||
120 | |||
121 | memmove(target_okbits, okbits, sizeof(okbits)); | ||
122 | return count; | 128 | return count; |
123 | } | 129 | } |
124 | 130 | ||