LCOV - code coverage report
Current view: top level - drivers/md - dm-sysfs.c (source / functions) Hit Total Coverage
Test: landlock.info Lines: 0 44 0.0 %
Date: 2021-04-22 12:43:58 Functions: 0 8 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 2008 Red Hat, Inc. All rights reserved.
       3             :  *
       4             :  * This file is released under the GPL.
       5             :  */
       6             : 
       7             : #include <linux/sysfs.h>
       8             : #include <linux/dm-ioctl.h>
       9             : #include "dm-core.h"
      10             : #include "dm-rq.h"
      11             : 
      12             : struct dm_sysfs_attr {
      13             :         struct attribute attr;
      14             :         ssize_t (*show)(struct mapped_device *, char *);
      15             :         ssize_t (*store)(struct mapped_device *, const char *, size_t count);
      16             : };
      17             : 
      18             : #define DM_ATTR_RO(_name) \
      19             : struct dm_sysfs_attr dm_attr_##_name = \
      20             :         __ATTR(_name, S_IRUGO, dm_attr_##_name##_show, NULL)
      21             : 
      22           0 : static ssize_t dm_attr_show(struct kobject *kobj, struct attribute *attr,
      23             :                             char *page)
      24             : {
      25           0 :         struct dm_sysfs_attr *dm_attr;
      26           0 :         struct mapped_device *md;
      27           0 :         ssize_t ret;
      28             : 
      29           0 :         dm_attr = container_of(attr, struct dm_sysfs_attr, attr);
      30           0 :         if (!dm_attr->show)
      31             :                 return -EIO;
      32             : 
      33           0 :         md = dm_get_from_kobject(kobj);
      34           0 :         if (!md)
      35             :                 return -EINVAL;
      36             : 
      37           0 :         ret = dm_attr->show(md, page);
      38           0 :         dm_put(md);
      39             : 
      40           0 :         return ret;
      41             : }
      42             : 
      43             : #define DM_ATTR_RW(_name) \
      44             : struct dm_sysfs_attr dm_attr_##_name = \
      45             :         __ATTR(_name, S_IRUGO | S_IWUSR, dm_attr_##_name##_show, dm_attr_##_name##_store)
      46             : 
      47           0 : static ssize_t dm_attr_store(struct kobject *kobj, struct attribute *attr,
      48             :                              const char *page, size_t count)
      49             : {
      50           0 :         struct dm_sysfs_attr *dm_attr;
      51           0 :         struct mapped_device *md;
      52           0 :         ssize_t ret;
      53             : 
      54           0 :         dm_attr = container_of(attr, struct dm_sysfs_attr, attr);
      55           0 :         if (!dm_attr->store)
      56             :                 return -EIO;
      57             : 
      58           0 :         md = dm_get_from_kobject(kobj);
      59           0 :         if (!md)
      60             :                 return -EINVAL;
      61             : 
      62           0 :         ret = dm_attr->store(md, page, count);
      63           0 :         dm_put(md);
      64             : 
      65           0 :         return ret;
      66             : }
      67             : 
      68           0 : static ssize_t dm_attr_name_show(struct mapped_device *md, char *buf)
      69             : {
      70           0 :         if (dm_copy_name_and_uuid(md, buf, NULL))
      71             :                 return -EIO;
      72             : 
      73           0 :         strcat(buf, "\n");
      74           0 :         return strlen(buf);
      75             : }
      76             : 
      77           0 : static ssize_t dm_attr_uuid_show(struct mapped_device *md, char *buf)
      78             : {
      79           0 :         if (dm_copy_name_and_uuid(md, NULL, buf))
      80             :                 return -EIO;
      81             : 
      82           0 :         strcat(buf, "\n");
      83           0 :         return strlen(buf);
      84             : }
      85             : 
      86           0 : static ssize_t dm_attr_suspended_show(struct mapped_device *md, char *buf)
      87             : {
      88           0 :         sprintf(buf, "%d\n", dm_suspended_md(md));
      89             : 
      90           0 :         return strlen(buf);
      91             : }
      92             : 
      93           0 : static ssize_t dm_attr_use_blk_mq_show(struct mapped_device *md, char *buf)
      94             : {
      95             :         /* Purely for userspace compatibility */
      96           0 :         sprintf(buf, "%d\n", true);
      97             : 
      98           0 :         return strlen(buf);
      99             : }
     100             : 
     101             : static DM_ATTR_RO(name);
     102             : static DM_ATTR_RO(uuid);
     103             : static DM_ATTR_RO(suspended);
     104             : static DM_ATTR_RO(use_blk_mq);
     105             : static DM_ATTR_RW(rq_based_seq_io_merge_deadline);
     106             : 
     107             : static struct attribute *dm_attrs[] = {
     108             :         &dm_attr_name.attr,
     109             :         &dm_attr_uuid.attr,
     110             :         &dm_attr_suspended.attr,
     111             :         &dm_attr_use_blk_mq.attr,
     112             :         &dm_attr_rq_based_seq_io_merge_deadline.attr,
     113             :         NULL,
     114             : };
     115             : 
     116             : static const struct sysfs_ops dm_sysfs_ops = {
     117             :         .show   = dm_attr_show,
     118             :         .store  = dm_attr_store,
     119             : };
     120             : 
     121             : static struct kobj_type dm_ktype = {
     122             :         .sysfs_ops      = &dm_sysfs_ops,
     123             :         .default_attrs  = dm_attrs,
     124             :         .release        = dm_kobject_release,
     125             : };
     126             : 
     127             : /*
     128             :  * Initialize kobj
     129             :  * because nobody using md yet, no need to call explicit dm_get/put
     130             :  */
     131           0 : int dm_sysfs_init(struct mapped_device *md)
     132             : {
     133           0 :         return kobject_init_and_add(dm_kobject(md), &dm_ktype,
     134           0 :                                     &disk_to_dev(dm_disk(md))->kobj,
     135             :                                     "%s", "dm");
     136             : }
     137             : 
     138             : /*
     139             :  * Remove kobj, called after all references removed
     140             :  */
     141           0 : void dm_sysfs_exit(struct mapped_device *md)
     142             : {
     143           0 :         struct kobject *kobj = dm_kobject(md);
     144           0 :         kobject_put(kobj);
     145           0 :         wait_for_completion(dm_get_completion_from_kobject(kobj));
     146           0 : }

Generated by: LCOV version 1.14