[zaptel-commits] tzafrir: branch tzafrir/sysfs r2932 - /team/tzafrir/sysfs/zaptel-base.c
SVN commits to the Zaptel project
zaptel-commits at lists.digium.com
Tue Aug 21 18:42:40 CDT 2007
Author: tzafrir
Date: Tue Aug 21 18:42:40 2007
New Revision: 2932
URL: http://svn.digium.com/view/zaptel?view=rev&rev=2932
Log:
sysfs now represents zaptel spans under /sys/bus/zaptel .
Spans have the following three example (RO) attributes:
* name - span name from struct zt_span.
* flags - span flags from struct zt_span.
* sync_master - Is this span the sync master?
zt_register also has an attempt to improve (non-existing) error handling.
Modified:
team/tzafrir/sysfs/zaptel-base.c
Modified: team/tzafrir/sysfs/zaptel-base.c
URL: http://svn.digium.com/view/zaptel/team/tzafrir/sysfs/zaptel-base.c?view=diff&rev=2932&r1=2931&r2=2932
==============================================================================
--- team/tzafrir/sysfs/zaptel-base.c (original)
+++ team/tzafrir/sysfs/zaptel-base.c Tue Aug 21 18:42:40 2007
@@ -58,6 +58,8 @@
#include <linux/if.h>
#include <linux/if_ppp.h>
#endif
+
+#define ZAP_DEVICE_MODEL
#ifndef CONFIG_OLD_HDLC_API
#define NEW_HDLC_INTERFACE
@@ -665,7 +667,7 @@
ssize_t name(struct device *dev, char *buf)
#endif
-/*--------- Sysfs Bus handling ----*/
+#ifdef ZAP_DEVICE_MODEL
/* Always match, because the zaptel core handles all devices. */
static int zap_bus_match(struct device *dev, struct device_driver *driver)
@@ -690,7 +692,7 @@
}
#else
-#define XBUS_ADD_UEVENT_VAR(fmt, val...) \
+#define SPAN_ADD_UEVENT_VAR(fmt, val...) \
do { \
int err = add_uevent_var(envp, num_envp, &i, \
buffer, buffer_size, &len, \
@@ -709,8 +711,8 @@
return -ENODEV;
span = dev_to_span(dev);
zap_dbg("bus_id=%s span=%s\n", dev->bus_id, span->name);
- XBUS_ADD_UEVENT_VAR("XBUS_NUM=%02d", span->spanno);
- XBUS_ADD_UEVENT_VAR("XBUS_NAME=%s", span->name);
+ SPAN_ADD_UEVENT_VAR("SPAN_NUM=%02d", span->spanno);
+ SPAN_ADD_UEVENT_VAR("SPAN_NAME=%s", span->name);
envp[i] = NULL;
return 0;
}
@@ -721,7 +723,7 @@
zap_dbg("\n");
}
-static void xpp_dev_release(struct device *dev)
+static void zap_dev_release(struct device *dev)
{
struct zt_span *span;
@@ -731,7 +733,7 @@
}
static struct bus_type zap_bus_type = {
- .name = "spans",
+ .name = "zaptel",
.match = zap_bus_match,
#ifdef OLD_HOPLUG_SUPPORT
.hotplug = zap_bus_hotplug,
@@ -741,19 +743,19 @@
};
static struct device zap_bus = {
- .bus_id = "xppbus",
+ .bus_id = "zapbus",
.release = zap_bus_release
};
-static struct device_driver xpp_driver = {
- .name = "xppdrv",
+static struct device_driver zap_driver = {
+ .name = "zapdrv",
.bus = &zap_bus_type,
#ifndef OLD_HOPLUG_SUPPORT
.owner = THIS_MODULE
#endif
};
-int register_zap_bus(void)
+static int register_zap_bus(void)
{
int ret;
@@ -766,7 +768,7 @@
__FUNCTION__, ret);
goto failed_busdevice;
}
- if((ret = driver_register(&xpp_driver)) < 0) {
+ if((ret = driver_register(&zap_driver)) < 0) {
zap_err("%s: driver_register failed. Error number %d", __FUNCTION__, ret);
goto failed_driver;
}
@@ -779,39 +781,38 @@
return ret;
}
-void unregister_zap_bus(void)
-{
- driver_unregister(&xpp_driver);
+static void unregister_zap_bus(void)
+{
+ driver_unregister(&zap_driver);
device_unregister(&zap_bus);
bus_unregister(&zap_bus_type);
}
/*--------- Sysfs Device handling ----*/
-static DEVICE_ATTR_FUNC(connector_show, dev, buf)
-{
- struct zt_span *span;
- int ret;
-
- span = dev_to_span(dev);
- ret = snprintf(buf, PAGE_SIZE, "%s\n", span->desc);
- return ret;
-}
+static DEVICE_ATTR_FUNC(flags_show, dev, buf)
+{
+ struct zt_span *span = dev_to_span(dev);
+ return snprintf(buf, PAGE_SIZE, "%x\n", span->flags);
+}
+static DEVICE_ATTR(flags, S_IRUGO, flags_show, NULL);
+
+static DEVICE_ATTR_FUNC(name_show, dev, buf)
+{
+ struct zt_span *span = dev_to_span(dev);
+ return snprintf(buf, PAGE_SIZE, "%s\n", span->name);
+}
+static DEVICE_ATTR(name, S_IRUGO, name_show, NULL);
/* FIXME: replace this attribute with something more useful */
-static DEVICE_ATTR_FUNC(status_show, dev, buf)
-{
- struct zt_span *span;
- int ret;
-
- span = dev_to_span(dev);
- ret = snprintf(buf, PAGE_SIZE, "%s\n", "connected");
- return ret;
-}
-
-static DEVICE_ATTR(connector, S_IRUGO, connector_show, NULL);
-static DEVICE_ATTR(status, S_IRUGO, status_show, NULL);
-
-void span_sysfs_remove(struct zt_span *span)
+static DEVICE_ATTR_FUNC(sync_master_show, dev, buf)
+{
+ struct zt_span *span = dev_to_span(dev);
+ return snprintf(buf, PAGE_SIZE, "%s\n", (span == master) ? "Y":"N");
+}
+static DEVICE_ATTR(sync_master, S_IRUGO, sync_master_show, NULL);
+
+
+static void span_sysfs_remove(struct zt_span *span)
{
struct device *device;
@@ -819,12 +820,13 @@
zap_dbg_span(span, "\n");
device = &span->device;
BUG_ON(!device);
- device_remove_file(&span->device, &dev_attr_status);
- device_remove_file(&span->device, &dev_attr_connector);
+ device_remove_file(&span->device, &dev_attr_flags);
+ device_remove_file(&span->device, &dev_attr_name);
+ device_remove_file(&span->device, &dev_attr_sync_master);
device_unregister(&span->device);
}
-int span_sysfs_create(struct zt_span *span)
+static int span_sysfs_create(struct zt_span *span)
{
struct device *device;
int ret = 0;
@@ -838,20 +840,25 @@
device->parent = &zap_bus;
snprintf(device->bus_id, BUS_ID_SIZE, "span-%02d", span->spanno);
device->driver_data = NULL; /* FIXME: add some usefull data */
- device->release = xpp_dev_release;
+ device->release = zap_dev_release;
ret = device_register(device);
if(ret) {
zap_err_span(span, "%s: device_add failed: %d\n", __FUNCTION__, ret);
goto out;
}
- ret = device_create_file(device, &dev_attr_connector);
+ ret = device_create_file(device, &dev_attr_flags);
if(ret) {
- zap_err_span(span, "%s: device_create_file failed: %d\n", __FUNCTION__, ret);
+ zap_err_span(span, "%s: device_create_file failed (flags): %d\n", __FUNCTION__, ret);
goto out;
}
- ret = device_create_file(device, &dev_attr_status);
+ ret = device_create_file(device, &dev_attr_name);
if(ret) {
- zap_err_span(span, "%s: device_create_file failed: %d\n", __FUNCTION__, ret);
+ zap_err_span(span, "%s: device_create_file failed (name): %d\n", __FUNCTION__, ret);
+ goto out;
+ }
+ ret = device_create_file(device, &dev_attr_sync_master);
+ if(ret) {
+ zap_err_span(span, "%s: device_create_file failed (sync_master): %d\n", __FUNCTION__, ret);
goto out;
}
out:
@@ -861,7 +868,7 @@
* End device Model Stuff
*
****************************************************/
-
+#endif /* ZAP_DEVICE_MODEL */
static int zt_first_empty_alias(void)
{
@@ -4893,7 +4900,7 @@
int zt_register(struct zt_span *span, int prefmaster)
{
- int x;
+ int x, ret;
#ifdef CONFIG_PROC_FS
char tempfile[17];
@@ -4934,9 +4941,16 @@
}
#ifdef CONFIG_PROC_FS
- sprintf(tempfile, "zaptel/%d", span->spanno);
- proc_entries[span->spanno] = create_proc_read_entry(tempfile, 0444, NULL , zaptel_proc_read, (int *)(long)span->spanno);
-#endif
+ sprintf(tempfile, "zaptel/%d", span->spanno);
+ proc_entries[span->spanno] = create_proc_read_entry(tempfile, 0444, NULL , zaptel_proc_read, (int *)(long)span->spanno);
+#endif
+#ifdef ZAP_DEVICE_MODEL
+ /* Device-Model */
+ if((ret = span_sysfs_create(span)) < 0) {
+ zap_err_span(span, "%s: span_sysfs_create() failed: %d\n", __FUNCTION__, ret);
+ goto err;
+ }
+#endif /* ZAP_DEVICE_MODEL */
#ifdef CONFIG_DEVFS_FS
{
@@ -4966,6 +4980,17 @@
printk("Span ('%s') is new master\n", span->name);
}
return 0;
+
+err:
+ if (proc_entries[span->spanno]) {
+ remove_proc_entry(tempfile, NULL);
+ proc_entries[span->spanno] = NULL;
+ }
+ for (x=0;x<span->channels;x++)
+ zt_chan_unreg(&span->chans[x]);
+ span->flags &= ~ZT_FLAG_REGISTERED;
+ spans[span->spanno] = NULL;
+ return ret;
}
int zt_unregister(struct zt_span *span)
@@ -4996,7 +5021,12 @@
#ifdef CONFIG_PROC_FS
sprintf(tempfile, "zaptel/%d", span->spanno);
remove_proc_entry(tempfile, NULL);
+ proc_entries[span->spanno] = NULL;
#endif /* CONFIG_PROC_FS */
+#ifdef ZAP_DEVICE_MODEL
+ zap_info_span(span, "Removing sysfs for span.\n");
+ span_sysfs_remove(span);
+#endif /* ZAP_DEVICE_MODEL */
#ifdef CONFIG_DEVFS_FS
for (x = 0; x < span->channels; x++) {
devfs_unregister(span->chans[x].fhandle);
@@ -7348,7 +7378,10 @@
#ifdef CONFIG_PROC_FS
proc_entries[0] = proc_mkdir("zaptel", NULL);
#endif
-
+#ifdef ZAP_DEVICE_MODEL
+ if((res = register_zap_bus()) < 0)
+ goto err;
+#endif /* ZAP_DEVICE_MODEL */
#ifdef CONFIG_ZAP_UDEV /* udev support functions */
zap_class = class_create(THIS_MODULE, "zaptel");
CLASS_DEV_CREATE(zap_class, MKDEV(ZT_MAJOR, 250), NULL, "zaptranscode");
@@ -7409,11 +7442,20 @@
watchdog_init();
#endif
return res;
+
+err:
+ /* release what we may hold, and exit */
+#ifdef CONFIG_PROC_FS
+ if (proc_entries[0])
+ remove_proc_entry("zaptel", NULL);
+#endif
+ return res;
}
static void __exit zt_cleanup(void) {
int x;
+ unregister_zap_bus();
#ifdef CONFIG_PROC_FS
remove_proc_entry("zaptel", NULL);
#endif
More information about the zaptel-commits
mailing list