Skip to content

Commit cd649b8

Browse files
Li ZefanIngo Molnar
authored andcommitted
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 <[email protected]> Acked-by: Frederic Weisbecker <[email protected]> Acked-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Steven Rostedt <[email protected]> LKML-Reference: <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent 15152e4 commit cd649b8

File tree

1 file changed

+22
-70
lines changed

1 file changed

+22
-70
lines changed

kernel/trace/blktrace.c

Lines changed: 22 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,72 +1284,6 @@ static int blk_trace_setup_queue(struct request_queue *q, dev_t dev)
12841284
* sysfs interface to enable and configure tracing
12851285
*/
12861286

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-
13531287
static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
13541288
struct device_attribute *attr,
13551289
char *buf);
@@ -1361,8 +1295,7 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
13611295
sysfs_blk_trace_attr_show, \
13621296
sysfs_blk_trace_attr_store)
13631297

1364-
static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR,
1365-
sysfs_blk_trace_enable_show, sysfs_blk_trace_enable_store);
1298+
static BLK_TRACE_DEVICE_ATTR(enable);
13661299
static BLK_TRACE_DEVICE_ATTR(act_mask);
13671300
static BLK_TRACE_DEVICE_ATTR(pid);
13681301
static BLK_TRACE_DEVICE_ATTR(start_lba);
@@ -1447,6 +1380,12 @@ static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
14471380
if (q == NULL)
14481381
goto out_bdput;
14491382
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+
14501389
if (q->blk_trace == NULL)
14511390
ret = sprintf(buf, "disabled\n");
14521391
else if (attr == &dev_attr_act_mask)
@@ -1457,6 +1396,8 @@ static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
14571396
ret = sprintf(buf, "%llu\n", q->blk_trace->start_lba);
14581397
else if (attr == &dev_attr_end_lba)
14591398
ret = sprintf(buf, "%llu\n", q->blk_trace->end_lba);
1399+
1400+
out_unlock_bdev:
14601401
mutex_unlock(&bdev->bd_mutex);
14611402
out_bdput:
14621403
bdput(bdev);
@@ -1499,6 +1440,15 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
14991440
goto out_bdput;
15001441

15011442
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+
15021452
ret = 0;
15031453
if (q->blk_trace == NULL)
15041454
ret = blk_trace_setup_queue(q, bdev->bd_dev);
@@ -1512,13 +1462,15 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
15121462
q->blk_trace->start_lba = value;
15131463
else if (attr == &dev_attr_end_lba)
15141464
q->blk_trace->end_lba = value;
1515-
ret = count;
15161465
}
1466+
1467+
out_unlock_bdev:
15171468
mutex_unlock(&bdev->bd_mutex);
15181469
out_bdput:
15191470
bdput(bdev);
15201471
out_unlock_kernel:
15211472
unlock_kernel();
15221473
out:
1523-
return ret;
1474+
return ret ? ret : count;
15241475
}
1476+

0 commit comments

Comments
 (0)