Source
x
/*
* Export the iSCSI boot info to userland via sysfs.
*
* Copyright (C) 2010 Red Hat, Inc. All rights reserved.
* Copyright (C) 2010 Mike Christie
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License v2.0 as published by
* the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>");
MODULE_DESCRIPTION("sysfs interface and helpers to export iSCSI boot information");
MODULE_LICENSE("GPL");
/*
* The kobject and attribute structures.
*/
struct iscsi_boot_attr {
struct attribute attr;
int type;
ssize_t (*show) (void *data, int type, char *buf);
};
/*
* The routine called for all sysfs attributes.
*/
static ssize_t iscsi_boot_show_attribute(struct kobject *kobj,
struct attribute *attr, char *buf)
{
struct iscsi_boot_kobj *boot_kobj =
container_of(kobj, struct iscsi_boot_kobj, kobj);
struct iscsi_boot_attr *boot_attr =
container_of(attr, struct iscsi_boot_attr, attr);
ssize_t ret = -EIO;
char *str = buf;
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
if (boot_kobj->show)
ret = boot_kobj->show(boot_kobj->data, boot_attr->type, str);
return ret;
}
static const struct sysfs_ops iscsi_boot_attr_ops = {
.show = iscsi_boot_show_attribute,
};
static void iscsi_boot_kobj_release(struct kobject *kobj)
{
struct iscsi_boot_kobj *boot_kobj =
container_of(kobj, struct iscsi_boot_kobj, kobj);
if (boot_kobj->release)
boot_kobj->release(boot_kobj->data);
kfree(boot_kobj);
}
static struct kobj_type iscsi_boot_ktype = {
.release = iscsi_boot_kobj_release,
.sysfs_ops = &iscsi_boot_attr_ops,
};
/* Target attrs */
iscsi_boot_rd_attr(tgt_index, index, ISCSI_BOOT_TGT_INDEX);
iscsi_boot_rd_attr(tgt_flags, flags, ISCSI_BOOT_TGT_FLAGS);
iscsi_boot_rd_attr(tgt_ip, ip-addr, ISCSI_BOOT_TGT_IP_ADDR);
iscsi_boot_rd_attr(tgt_port, port, ISCSI_BOOT_TGT_PORT);
iscsi_boot_rd_attr(tgt_lun, lun, ISCSI_BOOT_TGT_LUN);
iscsi_boot_rd_attr(tgt_chap, chap-type, ISCSI_BOOT_TGT_CHAP_TYPE);
iscsi_boot_rd_attr(tgt_nic, nic-assoc, ISCSI_BOOT_TGT_NIC_ASSOC);
iscsi_boot_rd_attr(tgt_name, target-name, ISCSI_BOOT_TGT_NAME);
iscsi_boot_rd_attr(tgt_chap_name, chap-name, ISCSI_BOOT_TGT_CHAP_NAME);