ia64/kvm: compilation fix. export account_system_vtime.
[pv_ops_mirror.git] / drivers / s390 / scsi / zfcp_sysfs_unit.c
blob80fb2c2cf48ae6bdb162be9f25000e6ef988ed9d
1 /*
2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "zfcp_ext.h"
24 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
26 /**
27 * zfcp_sysfs_unit_release - gets called when a struct device unit is released
28 * @dev: pointer to belonging device
30 void
31 zfcp_sysfs_unit_release(struct device *dev)
33 kfree(dev);
36 /**
37 * ZFCP_DEFINE_UNIT_ATTR
38 * @_name: name of show attribute
39 * @_format: format string
40 * @_value: value to print
42 * Generates attribute for a unit.
44 #define ZFCP_DEFINE_UNIT_ATTR(_name, _format, _value) \
45 static ssize_t zfcp_sysfs_unit_##_name##_show(struct device *dev, struct device_attribute *attr, \
46 char *buf) \
47 { \
48 struct zfcp_unit *unit; \
50 unit = dev_get_drvdata(dev); \
51 return sprintf(buf, _format, _value); \
52 } \
54 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_unit_##_name##_show, NULL);
56 ZFCP_DEFINE_UNIT_ATTR(status, "0x%08x\n", atomic_read(&unit->status));
57 ZFCP_DEFINE_UNIT_ATTR(in_recovery, "%d\n", atomic_test_mask
58 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status));
59 ZFCP_DEFINE_UNIT_ATTR(access_denied, "%d\n", atomic_test_mask
60 (ZFCP_STATUS_COMMON_ACCESS_DENIED, &unit->status));
61 ZFCP_DEFINE_UNIT_ATTR(access_shared, "%d\n", atomic_test_mask
62 (ZFCP_STATUS_UNIT_SHARED, &unit->status));
63 ZFCP_DEFINE_UNIT_ATTR(access_readonly, "%d\n", atomic_test_mask
64 (ZFCP_STATUS_UNIT_READONLY, &unit->status));
66 /**
67 * zfcp_sysfs_unit_failed_store - failed state of unit
68 * @dev: pointer to belonging device
69 * @buf: pointer to input buffer
70 * @count: number of bytes in buffer
72 * Store function of the "failed" attribute of a unit.
73 * If a "0" gets written to "failed", error recovery will be
74 * started for the belonging unit.
76 static ssize_t
77 zfcp_sysfs_unit_failed_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
79 struct zfcp_unit *unit;
80 unsigned int val;
81 char *endp;
82 int retval = 0;
84 down(&zfcp_data.config_sema);
85 unit = dev_get_drvdata(dev);
86 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status)) {
87 retval = -EBUSY;
88 goto out;
91 val = simple_strtoul(buf, &endp, 0);
92 if (((endp + 1) < (buf + count)) || (val != 0)) {
93 retval = -EINVAL;
94 goto out;
97 zfcp_erp_modify_unit_status(unit, 46, NULL,
98 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
99 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, 97, NULL);
100 zfcp_erp_wait(unit->port->adapter);
101 out:
102 up(&zfcp_data.config_sema);
103 return retval ? retval : (ssize_t) count;
107 * zfcp_sysfs_unit_failed_show - failed state of unit
108 * @dev: pointer to belonging device
109 * @buf: pointer to input buffer
111 * Show function of "failed" attribute of unit. Will be
112 * "0" if unit is working, otherwise "1".
114 static ssize_t
115 zfcp_sysfs_unit_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
117 struct zfcp_unit *unit;
119 unit = dev_get_drvdata(dev);
120 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status))
121 return sprintf(buf, "1\n");
122 else
123 return sprintf(buf, "0\n");
126 static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_unit_failed_show,
127 zfcp_sysfs_unit_failed_store);
129 static struct attribute *zfcp_unit_attrs[] = {
130 &dev_attr_failed.attr,
131 &dev_attr_in_recovery.attr,
132 &dev_attr_status.attr,
133 &dev_attr_access_denied.attr,
134 &dev_attr_access_shared.attr,
135 &dev_attr_access_readonly.attr,
136 NULL
139 static struct attribute_group zfcp_unit_attr_group = {
140 .attrs = zfcp_unit_attrs,
144 * zfcp_sysfs_create_unit_files - create sysfs unit files
145 * @dev: pointer to belonging device
147 * Create all attributes of the sysfs representation of a unit.
150 zfcp_sysfs_unit_create_files(struct device *dev)
152 return sysfs_create_group(&dev->kobj, &zfcp_unit_attr_group);
156 * zfcp_sysfs_remove_unit_files - remove sysfs unit files
157 * @dev: pointer to belonging device
159 * Remove all attributes of the sysfs representation of a unit.
161 void
162 zfcp_sysfs_unit_remove_files(struct device *dev)
164 sysfs_remove_group(&dev->kobj, &zfcp_unit_attr_group);
167 #undef ZFCP_LOG_AREA