aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2006-01-06 03:20:41 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-01-06 11:34:07 -0500
commitbce74dac082787375e76d2b33726b94c9701fabc (patch)
treec653fdadc41cf35daae7455f794caec42cff05f0
parent1345b1d8adbdeceb1c871d9a4af5e2a700b341c6 (diff)
[PATCH] md: helper function to match commands written to sysfs files
Commands written to sysfs files may, or my not, be \n terminated. We want to accept with case. For this we use cmd_match. Signed-off-by: Neil Brown <neilb@suse.de> Acked-by: Greg KH <greg@kroah.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--drivers/md/md.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 07f180f95b4..c1613854f38 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1525,6 +1525,26 @@ repeat:
1525 1525
1526} 1526}
1527 1527
1528/* words written to sysfs files may, or my not, be \n terminated.
1529 * We want to accept with case. For this we use cmd_match.
1530 */
1531static int cmd_match(const char *cmd, const char *str)
1532{
1533 /* See if cmd, written into a sysfs file, matches
1534 * str. They must either be the same, or cmd can
1535 * have a trailing newline
1536 */
1537 while (*cmd && *str && *cmd == *str) {
1538 cmd++;
1539 str++;
1540 }
1541 if (*cmd == '\n')
1542 cmd++;
1543 if (*str || *cmd)
1544 return 0;
1545 return 1;
1546}
1547
1528struct rdev_sysfs_entry { 1548struct rdev_sysfs_entry {
1529 struct attribute attr; 1549 struct attribute attr;
1530 ssize_t (*show)(mdk_rdev_t *, char *); 1550 ssize_t (*show)(mdk_rdev_t *, char *);
@@ -1799,7 +1819,7 @@ action_store(mddev_t *mddev, const char *page, size_t len)
1799 if (!mddev->pers || !mddev->pers->sync_request) 1819 if (!mddev->pers || !mddev->pers->sync_request)
1800 return -EINVAL; 1820 return -EINVAL;
1801 1821
1802 if (strcmp(page, "idle")==0 || strcmp(page, "idle\n")==0) { 1822 if (cmd_match(page, "idle")) {
1803 if (mddev->sync_thread) { 1823 if (mddev->sync_thread) {
1804 set_bit(MD_RECOVERY_INTR, &mddev->recovery); 1824 set_bit(MD_RECOVERY_INTR, &mddev->recovery);
1805 md_unregister_thread(mddev->sync_thread); 1825 md_unregister_thread(mddev->sync_thread);
@@ -1812,13 +1832,12 @@ action_store(mddev_t *mddev, const char *page, size_t len)
1812 if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || 1832 if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
1813 test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) 1833 test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))
1814 return -EBUSY; 1834 return -EBUSY;
1815 if (strcmp(page, "resync")==0 || strcmp(page, "resync\n")==0 || 1835 if (cmd_match(page, "resync") || cmd_match(page, "recover"))
1816 strcmp(page, "recover")==0 || strcmp(page, "recover\n")==0)
1817 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 1836 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
1818 else { 1837 else {
1819 if (strcmp(page, "check")==0 || strcmp(page, "check\n")==0) 1838 if (cmd_match(page, "check"))
1820 set_bit(MD_RECOVERY_CHECK, &mddev->recovery); 1839 set_bit(MD_RECOVERY_CHECK, &mddev->recovery);
1821 else if (strcmp(page, "repair")!=0 && strcmp(page, "repair\n")!=0) 1840 else if (cmd_match(page, "repair"))
1822 return -EINVAL; 1841 return -EINVAL;
1823 set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); 1842 set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery);
1824 set_bit(MD_RECOVERY_SYNC, &mddev->recovery); 1843 set_bit(MD_RECOVERY_SYNC, &mddev->recovery);