aufs: debug, from aufs2.2-3.0
[zen-stable.git] / fs / aufs / procfs.c
blob42da6d809cb5675c5f136426cdeb106d883828af
1 /*
2 * Copyright (C) 2010-2011 Junjiro R. Okajima
4 * This program, aufs is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * procfs interfaces
23 #include <linux/proc_fs.h>
24 #include "aufs.h"
26 static int au_procfs_plm_release(struct inode *inode, struct file *file)
28 struct au_sbinfo *sbinfo;
30 sbinfo = file->private_data;
31 if (sbinfo) {
32 au_plink_maint_leave(sbinfo);
33 kobject_put(&sbinfo->si_kobj);
36 return 0;
39 static void au_procfs_plm_write_clean(struct file *file)
41 struct au_sbinfo *sbinfo;
43 sbinfo = file->private_data;
44 if (sbinfo)
45 au_plink_clean(sbinfo->si_sb, /*verbose*/0);
48 static int au_procfs_plm_write_si(struct file *file, unsigned long id)
50 int err;
51 struct super_block *sb;
52 struct au_sbinfo *sbinfo;
54 err = -EBUSY;
55 if (unlikely(file->private_data))
56 goto out;
58 sb = NULL;
59 /* don't use au_sbilist_lock() here */
60 spin_lock(&au_sbilist.spin);
61 list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
62 if (id == sysaufs_si_id(sbinfo)) {
63 kobject_get(&sbinfo->si_kobj);
64 sb = sbinfo->si_sb;
65 break;
67 spin_unlock(&au_sbilist.spin);
69 err = -EINVAL;
70 if (unlikely(!sb))
71 goto out;
73 err = au_plink_maint_enter(sb);
74 if (!err)
75 /* keep kobject_get() */
76 file->private_data = sbinfo;
77 else
78 kobject_put(&sbinfo->si_kobj);
79 out:
80 return err;
84 * Accept a valid "si=xxxx" only.
85 * Once it is accepted successfully, accept "clean" too.
87 static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
88 size_t count, loff_t *ppos)
90 ssize_t err;
91 unsigned long id;
92 /* last newline is allowed */
93 char buf[3 + sizeof(unsigned long) * 2 + 1];
95 err = -EACCES;
96 if (unlikely(!capable(CAP_SYS_ADMIN)))
97 goto out;
99 err = -EINVAL;
100 if (unlikely(count > sizeof(buf)))
101 goto out;
103 err = copy_from_user(buf, ubuf, count);
104 if (unlikely(err)) {
105 err = -EFAULT;
106 goto out;
108 buf[count] = 0;
110 err = -EINVAL;
111 if (!strcmp("clean", buf)) {
112 au_procfs_plm_write_clean(file);
113 goto out_success;
114 } else if (unlikely(strncmp("si=", buf, 3)))
115 goto out;
117 err = strict_strtoul(buf + 3, 16, &id);
118 if (unlikely(err))
119 goto out;
121 err = au_procfs_plm_write_si(file, id);
122 if (unlikely(err))
123 goto out;
125 out_success:
126 err = count; /* success */
127 out:
128 return err;
131 static const struct file_operations au_procfs_plm_fop = {
132 .write = au_procfs_plm_write,
133 .release = au_procfs_plm_release,
134 .owner = THIS_MODULE
137 /* ---------------------------------------------------------------------- */
139 static struct proc_dir_entry *au_procfs_dir;
141 void au_procfs_fin(void)
143 remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
144 remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
147 int __init au_procfs_init(void)
149 int err;
150 struct proc_dir_entry *entry;
152 err = -ENOMEM;
153 au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
154 if (unlikely(!au_procfs_dir))
155 goto out;
157 entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
158 au_procfs_dir, &au_procfs_plm_fop);
159 if (unlikely(!entry))
160 goto out_dir;
162 err = 0;
163 goto out; /* success */
166 out_dir:
167 remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
168 out:
169 return err;