Skip to content

Commit 74ae4e1

Browse files
Joel BeckerMark Fasheh
authored andcommitted
ocfs2: Create stack glue sysfs files.
Introduce a set of sysfs files that describe the current stack glue state. The files live under /sys/fs/ocfs2. The locking_protocol file displays the version of ocfs2's locking code. The loaded_cluster_plugins file displays all of the currently loaded stack plugins. When filesystems are mounted, the active_cluster_plugin file will display the plugin in use. Signed-off-by: Joel Becker <joel.becker@oracle.com> Signed-off-by: Mark Fasheh <mfasheh@suse.com>
1 parent 286eaa9 commit 74ae4e1

1 file changed

Lines changed: 120 additions & 1 deletion

File tree

‎fs/ocfs2/stackglue.c‎

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include <linux/module.h>
2424
#include <linux/slab.h>
2525
#include <linux/kmod.h>
26+
#include <linux/fs.h>
27+
#include <linux/kobject.h>
28+
#include <linux/sysfs.h>
2629

2730
#include "stackglue.h"
2831

@@ -335,14 +338,130 @@ int ocfs2_cluster_this_node(unsigned int *node)
335338
EXPORT_SYMBOL_GPL(ocfs2_cluster_this_node);
336339

337340

338-
static int __init ocfs2_stack_glue_init(void)
341+
/*
342+
* Sysfs bits
343+
*/
344+
345+
static ssize_t ocfs2_max_locking_protocol_show(struct kobject *kobj,
346+
struct kobj_attribute *attr,
347+
char *buf)
348+
{
349+
ssize_t ret = 0;
350+
351+
spin_lock(&ocfs2_stack_lock);
352+
if (lproto)
353+
ret = snprintf(buf, PAGE_SIZE, "%u.%u\n",
354+
lproto->lp_max_version.pv_major,
355+
lproto->lp_max_version.pv_minor);
356+
spin_unlock(&ocfs2_stack_lock);
357+
358+
return ret;
359+
}
360+
361+
static struct kobj_attribute ocfs2_attr_max_locking_protocol =
362+
__ATTR(max_locking_protocol, S_IFREG | S_IRUGO,
363+
ocfs2_max_locking_protocol_show, NULL);
364+
365+
static ssize_t ocfs2_loaded_cluster_plugins_show(struct kobject *kobj,
366+
struct kobj_attribute *attr,
367+
char *buf)
339368
{
369+
ssize_t ret = 0, total = 0, remain = PAGE_SIZE;
370+
struct ocfs2_stack_plugin *p;
371+
372+
spin_lock(&ocfs2_stack_lock);
373+
list_for_each_entry(p, &ocfs2_stack_list, sp_list) {
374+
ret = snprintf(buf, remain, "%s\n",
375+
p->sp_name);
376+
if (ret < 0) {
377+
total = ret;
378+
break;
379+
}
380+
if (ret == remain) {
381+
/* snprintf() didn't fit */
382+
total = -E2BIG;
383+
break;
384+
}
385+
total += ret;
386+
remain -= ret;
387+
}
388+
spin_unlock(&ocfs2_stack_lock);
389+
390+
return total;
391+
}
392+
393+
static struct kobj_attribute ocfs2_attr_loaded_cluster_plugins =
394+
__ATTR(loaded_cluster_plugins, S_IFREG | S_IRUGO,
395+
ocfs2_loaded_cluster_plugins_show, NULL);
396+
397+
static ssize_t ocfs2_active_cluster_plugin_show(struct kobject *kobj,
398+
struct kobj_attribute *attr,
399+
char *buf)
400+
{
401+
ssize_t ret = 0;
402+
403+
spin_lock(&ocfs2_stack_lock);
404+
if (active_stack) {
405+
ret = snprintf(buf, PAGE_SIZE, "%s\n",
406+
active_stack->sp_name);
407+
if (ret == PAGE_SIZE)
408+
ret = -E2BIG;
409+
}
410+
spin_unlock(&ocfs2_stack_lock);
411+
412+
return ret;
413+
}
414+
415+
static struct kobj_attribute ocfs2_attr_active_cluster_plugin =
416+
__ATTR(active_cluster_plugin, S_IFREG | S_IRUGO,
417+
ocfs2_active_cluster_plugin_show, NULL);
418+
419+
static struct attribute *ocfs2_attrs[] = {
420+
&ocfs2_attr_max_locking_protocol.attr,
421+
&ocfs2_attr_loaded_cluster_plugins.attr,
422+
&ocfs2_attr_active_cluster_plugin.attr,
423+
NULL,
424+
};
425+
426+
static struct attribute_group ocfs2_attr_group = {
427+
.attrs = ocfs2_attrs,
428+
};
429+
430+
static struct kset *ocfs2_kset;
431+
432+
static void ocfs2_sysfs_exit(void)
433+
{
434+
kset_unregister(ocfs2_kset);
435+
}
436+
437+
static int ocfs2_sysfs_init(void)
438+
{
439+
int ret;
440+
441+
ocfs2_kset = kset_create_and_add("ocfs2", NULL, fs_kobj);
442+
if (!ocfs2_kset)
443+
return -ENOMEM;
444+
445+
ret = sysfs_create_group(&ocfs2_kset->kobj, &ocfs2_attr_group);
446+
if (ret)
447+
goto error;
448+
340449
return 0;
450+
451+
error:
452+
kset_unregister(ocfs2_kset);
453+
return ret;
454+
}
455+
456+
static int __init ocfs2_stack_glue_init(void)
457+
{
458+
return ocfs2_sysfs_init();
341459
}
342460

343461
static void __exit ocfs2_stack_glue_exit(void)
344462
{
345463
lproto = NULL;
464+
ocfs2_sysfs_exit();
346465
}
347466

348467
MODULE_AUTHOR("Oracle");

0 commit comments

Comments
 (0)