diff options
author | Li Zefan <lizf@cn.fujitsu.com> | 2009-03-19 23:33:55 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-03-21 11:17:08 -0400 |
commit | cd649b8bb830d65c57c3c8b98d57b5402256d8bd (patch) | |
tree | e1cfb4a2d6a14f6459913ba7b40cc778f1fcb723 | |
parent | 15152e448b693fa41de40f1e40ffbe717a3aab88 (diff) |
blktrace: remove sysfs_blk_trace_enable_show/store()
sysfs_blk_trace_enable_show()/store() share most of code with
sysfs_blk_trace_attr_show()/store().
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <49C30EA3.1060004@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | kernel/trace/blktrace.c | 92 |
1 files changed, 22 insertions, 70 deletions
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 14986afdbc1c..dfee6f915179 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c | |||
@@ -1284,72 +1284,6 @@ static int blk_trace_setup_queue(struct request_queue *q, dev_t dev) | |||
1284 | * sysfs interface to enable and configure tracing | 1284 | * sysfs interface to enable and configure tracing |
1285 | */ | 1285 | */ |
1286 | 1286 | ||
1287 | static ssize_t sysfs_blk_trace_enable_show(struct device *dev, | ||
1288 | struct device_attribute *attr, | ||
1289 | char *buf) | ||
1290 | { | ||
1291 | struct hd_struct *p = dev_to_part(dev); | ||
1292 | struct block_device *bdev; | ||
1293 | ssize_t ret = -ENXIO; | ||
1294 | |||
1295 | lock_kernel(); | ||
1296 | bdev = bdget(part_devt(p)); | ||
1297 | if (bdev != NULL) { | ||
1298 | struct request_queue *q = bdev_get_queue(bdev); | ||
1299 | |||
1300 | if (q != NULL) { | ||
1301 | mutex_lock(&bdev->bd_mutex); | ||
1302 | ret = sprintf(buf, "%u\n", !!q->blk_trace); | ||
1303 | mutex_unlock(&bdev->bd_mutex); | ||
1304 | } | ||
1305 | |||
1306 | bdput(bdev); | ||
1307 | } | ||
1308 | |||
1309 | unlock_kernel(); | ||
1310 | return ret; | ||
1311 | } | ||
1312 | |||
1313 | static ssize_t sysfs_blk_trace_enable_store(struct device *dev, | ||
1314 | struct device_attribute *attr, | ||
1315 | const char *buf, size_t count) | ||
1316 | { | ||
1317 | struct block_device *bdev; | ||
1318 | struct request_queue *q; | ||
1319 | struct hd_struct *p; | ||
1320 | int value; | ||
1321 | ssize_t ret = -ENXIO; | ||
1322 | |||
1323 | if (count == 0 || sscanf(buf, "%d", &value) != 1) | ||
1324 | goto out; | ||
1325 | |||
1326 | lock_kernel(); | ||
1327 | p = dev_to_part(dev); | ||
1328 | bdev = bdget(part_devt(p)); | ||
1329 | if (bdev == NULL) | ||
1330 | goto out_unlock_kernel; | ||
1331 | |||
1332 | q = bdev_get_queue(bdev); | ||
1333 | if (q == NULL) | ||
1334 | goto out_bdput; | ||
1335 | |||
1336 | mutex_lock(&bdev->bd_mutex); | ||
1337 | if (value) | ||
1338 | ret = blk_trace_setup_queue(q, bdev->bd_dev); | ||
1339 | else | ||
1340 | ret = blk_trace_remove_queue(q); | ||
1341 | mutex_unlock(&bdev->bd_mutex); | ||
1342 | |||
1343 | if (ret == 0) | ||
1344 | ret = count; | ||
1345 | out_bdput: | ||
1346 | bdput(bdev); | ||
1347 | out_unlock_kernel: | ||
1348 | unlock_kernel(); | ||
1349 | out: | ||
1350 | return ret; | ||
1351 | } | ||
1352 | |||
1353 | static ssize_t sysfs_blk_trace_attr_show(struct device *dev, | 1287 | static ssize_t sysfs_blk_trace_attr_show(struct device *dev, |
1354 | struct device_attribute *attr, | 1288 | struct device_attribute *attr, |
1355 | char *buf); | 1289 | char *buf); |
@@ -1361,8 +1295,7 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev, | |||
1361 | sysfs_blk_trace_attr_show, \ | 1295 | sysfs_blk_trace_attr_show, \ |
1362 | sysfs_blk_trace_attr_store) | 1296 | sysfs_blk_trace_attr_store) |
1363 | 1297 | ||
1364 | static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, | 1298 | static BLK_TRACE_DEVICE_ATTR(enable); |
1365 | sysfs_blk_trace_enable_show, sysfs_blk_trace_enable_store); | ||
1366 | static BLK_TRACE_DEVICE_ATTR(act_mask); | 1299 | static BLK_TRACE_DEVICE_ATTR(act_mask); |
1367 | static BLK_TRACE_DEVICE_ATTR(pid); | 1300 | static BLK_TRACE_DEVICE_ATTR(pid); |
1368 | static BLK_TRACE_DEVICE_ATTR(start_lba); | 1301 | static BLK_TRACE_DEVICE_ATTR(start_lba); |
@@ -1447,6 +1380,12 @@ static ssize_t sysfs_blk_trace_attr_show(struct device *dev, | |||
1447 | if (q == NULL) | 1380 | if (q == NULL) |
1448 | goto out_bdput; | 1381 | goto out_bdput; |
1449 | mutex_lock(&bdev->bd_mutex); | 1382 | mutex_lock(&bdev->bd_mutex); |
1383 | |||
1384 | if (attr == &dev_attr_enable) { | ||
1385 | ret = sprintf(buf, "%u\n", !!q->blk_trace); | ||
1386 | goto out_unlock_bdev; | ||
1387 | } | ||
1388 | |||
1450 | if (q->blk_trace == NULL) | 1389 | if (q->blk_trace == NULL) |
1451 | ret = sprintf(buf, "disabled\n"); | 1390 | ret = sprintf(buf, "disabled\n"); |
1452 | else if (attr == &dev_attr_act_mask) | 1391 | else if (attr == &dev_attr_act_mask) |
@@ -1457,6 +1396,8 @@ static ssize_t sysfs_blk_trace_attr_show(struct device *dev, | |||
1457 | ret = sprintf(buf, "%llu\n", q->blk_trace->start_lba); | 1396 | ret = sprintf(buf, "%llu\n", q->blk_trace->start_lba); |
1458 | else if (attr == &dev_attr_end_lba) | 1397 | else if (attr == &dev_attr_end_lba) |
1459 | ret = sprintf(buf, "%llu\n", q->blk_trace->end_lba); | 1398 | ret = sprintf(buf, "%llu\n", q->blk_trace->end_lba); |
1399 | |||
1400 | out_unlock_bdev: | ||
1460 | mutex_unlock(&bdev->bd_mutex); | 1401 | mutex_unlock(&bdev->bd_mutex); |
1461 | out_bdput: | 1402 | out_bdput: |
1462 | bdput(bdev); | 1403 | bdput(bdev); |
@@ -1499,6 +1440,15 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev, | |||
1499 | goto out_bdput; | 1440 | goto out_bdput; |
1500 | 1441 | ||
1501 | mutex_lock(&bdev->bd_mutex); | 1442 | mutex_lock(&bdev->bd_mutex); |
1443 | |||
1444 | if (attr == &dev_attr_enable) { | ||
1445 | if (value) | ||
1446 | ret = blk_trace_setup_queue(q, bdev->bd_dev); | ||
1447 | else | ||
1448 | ret = blk_trace_remove_queue(q); | ||
1449 | goto out_unlock_bdev; | ||
1450 | } | ||
1451 | |||
1502 | ret = 0; | 1452 | ret = 0; |
1503 | if (q->blk_trace == NULL) | 1453 | if (q->blk_trace == NULL) |
1504 | ret = blk_trace_setup_queue(q, bdev->bd_dev); | 1454 | ret = blk_trace_setup_queue(q, bdev->bd_dev); |
@@ -1512,13 +1462,15 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev, | |||
1512 | q->blk_trace->start_lba = value; | 1462 | q->blk_trace->start_lba = value; |
1513 | else if (attr == &dev_attr_end_lba) | 1463 | else if (attr == &dev_attr_end_lba) |
1514 | q->blk_trace->end_lba = value; | 1464 | q->blk_trace->end_lba = value; |
1515 | ret = count; | ||
1516 | } | 1465 | } |
1466 | |||
1467 | out_unlock_bdev: | ||
1517 | mutex_unlock(&bdev->bd_mutex); | 1468 | mutex_unlock(&bdev->bd_mutex); |
1518 | out_bdput: | 1469 | out_bdput: |
1519 | bdput(bdev); | 1470 | bdput(bdev); |
1520 | out_unlock_kernel: | 1471 | out_unlock_kernel: |
1521 | unlock_kernel(); | 1472 | unlock_kernel(); |
1522 | out: | 1473 | out: |
1523 | return ret; | 1474 | return ret ? ret : count; |
1524 | } | 1475 | } |
1476 | |||