Skip to content

Commit 1366251

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: factor out flag_{store,show} helper for integrity
Factor the duplicate code for the generate and verify attributes into common helpers. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Keith Busch <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent e8bc14d commit 1366251

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

block/blk-integrity.c

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,28 @@ const char *blk_integrity_profile_name(struct blk_integrity *bi)
243243
}
244244
EXPORT_SYMBOL_GPL(blk_integrity_profile_name);
245245

246+
static ssize_t flag_store(struct device *dev, struct device_attribute *attr,
247+
const char *page, size_t count, unsigned char flag)
248+
{
249+
struct blk_integrity *bi = dev_to_bi(dev);
250+
char *p = (char *) page;
251+
unsigned long val = simple_strtoul(p, &p, 10);
252+
253+
if (val)
254+
bi->flags |= flag;
255+
else
256+
bi->flags &= ~flag;
257+
return count;
258+
}
259+
260+
static ssize_t flag_show(struct device *dev, struct device_attribute *attr,
261+
char *page, unsigned char flag)
262+
{
263+
struct blk_integrity *bi = dev_to_bi(dev);
264+
265+
return sysfs_emit(page, "%d\n", !!(bi->flags & flag));
266+
}
267+
246268
static ssize_t format_show(struct device *dev, struct device_attribute *attr,
247269
char *page)
248270
{
@@ -275,49 +297,26 @@ static ssize_t read_verify_store(struct device *dev,
275297
struct device_attribute *attr,
276298
const char *page, size_t count)
277299
{
278-
struct blk_integrity *bi = dev_to_bi(dev);
279-
char *p = (char *) page;
280-
unsigned long val = simple_strtoul(p, &p, 10);
281-
282-
if (val)
283-
bi->flags |= BLK_INTEGRITY_VERIFY;
284-
else
285-
bi->flags &= ~BLK_INTEGRITY_VERIFY;
286-
287-
return count;
300+
return flag_store(dev, attr, page, count, BLK_INTEGRITY_VERIFY);
288301
}
289302

290303
static ssize_t read_verify_show(struct device *dev,
291304
struct device_attribute *attr, char *page)
292305
{
293-
struct blk_integrity *bi = dev_to_bi(dev);
294-
295-
return sysfs_emit(page, "%d\n", !!(bi->flags & BLK_INTEGRITY_VERIFY));
306+
return flag_show(dev, attr, page, BLK_INTEGRITY_VERIFY);
296307
}
297308

298309
static ssize_t write_generate_store(struct device *dev,
299310
struct device_attribute *attr,
300311
const char *page, size_t count)
301312
{
302-
struct blk_integrity *bi = dev_to_bi(dev);
303-
304-
char *p = (char *) page;
305-
unsigned long val = simple_strtoul(p, &p, 10);
306-
307-
if (val)
308-
bi->flags |= BLK_INTEGRITY_GENERATE;
309-
else
310-
bi->flags &= ~BLK_INTEGRITY_GENERATE;
311-
312-
return count;
313+
return flag_store(dev, attr, page, count, BLK_INTEGRITY_GENERATE);
313314
}
314315

315316
static ssize_t write_generate_show(struct device *dev,
316317
struct device_attribute *attr, char *page)
317318
{
318-
struct blk_integrity *bi = dev_to_bi(dev);
319-
320-
return sysfs_emit(page, "%d\n", !!(bi->flags & BLK_INTEGRITY_GENERATE));
319+
return flag_show(dev, attr, page, BLK_INTEGRITY_GENERATE);
321320
}
322321

323322
static ssize_t device_is_integrity_capable_show(struct device *dev,

0 commit comments

Comments
 (0)