summaryrefslogtreecommitdiff
path: root/fs/aufs/sysaufs.c
blob: 29ac6faa68ad3b713c822acc528eba7c4f7c5ad9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * Copyright (C) 2005-2015 Junjiro R. Okajima
 */

/*
 * sysfs interface and lifetime management
 * they are necessary regardless sysfs is disabled.
 */

#include <linux/random.h>
#include "aufs.h"

unsigned long sysaufs_si_mask;
struct kset *sysaufs_kset;

#define AuSiAttr(_name) { \
	.attr   = { .name = __stringify(_name), .mode = 0444 },	\
	.show   = sysaufs_si_##_name,				\
}

static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
struct attribute *sysaufs_si_attrs[] = {
	&sysaufs_si_attr_xi_path.attr,
	NULL,
};

static const struct sysfs_ops au_sbi_ops = {
	.show   = sysaufs_si_show
};

static struct kobj_type au_sbi_ktype = {
	.release	= au_si_free,
	.sysfs_ops	= &au_sbi_ops,
	.default_attrs	= sysaufs_si_attrs
};

/* ---------------------------------------------------------------------- */

int sysaufs_si_init(struct au_sbinfo *sbinfo)
{
	int err;

	sbinfo->si_kobj.kset = sysaufs_kset;
	/* cf. sysaufs_name() */
	err = kobject_init_and_add
		(&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
		 SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));

	dbgaufs_si_null(sbinfo);
	if (!err) {
		err = dbgaufs_si_init(sbinfo);
		if (unlikely(err))
			kobject_put(&sbinfo->si_kobj);
	}
	return err;
}

void sysaufs_fin(void)
{
	dbgaufs_fin();
	sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
	kset_unregister(sysaufs_kset);
}

int __init sysaufs_init(void)
{
	int err;

	do {
		get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
	} while (!sysaufs_si_mask);

	err = -EINVAL;
	sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
	if (unlikely(!sysaufs_kset))
		goto out;
	err = PTR_ERR(sysaufs_kset);
	if (IS_ERR(sysaufs_kset))
		goto out;
	err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
	if (unlikely(err)) {
		kset_unregister(sysaufs_kset);
		goto out;
	}

	err = dbgaufs_init();
	if (unlikely(err))
		sysaufs_fin();
out:
	return err;
}