blob: 0593b229656cae1f4b195ee997face59dc7a25c5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Quota code necessary even when VFS quota support is not compiled
3 * into the kernel. The interesting stuff is over in dquot.c, here
4 * we have symbols for initial quotactl(2) handling, the sysctl(2)
5 * variables, etc - things needed even when quota support disabled.
6 */
7
8#include <linux/fs.h>
9#include <linux/namei.h>
10#include <linux/slab.h>
11#include <asm/current.h>
12#include <asm/uaccess.h>
Vasily Tarasovb7163952007-07-15 23:41:12 -070013#include <linux/compat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/security.h>
16#include <linux/syscalls.h>
17#include <linux/buffer_head.h>
Randy Dunlap16f7e0f2006-01-11 12:17:46 -080018#include <linux/capability.h>
Adrian Bunkbe586ba2005-11-07 00:59:35 -080019#include <linux/quotaops.h>
Vasily Tarasovb7163952007-07-15 23:41:12 -070020#include <linux/types.h>
Christoph Hellwig8c4e4ac2010-02-16 03:44:51 -050021#include <linux/writeback.h>
Steven Whitehouse86e931a2009-09-28 12:35:17 +010022#include <net/netlink.h>
23#include <net/genetlink.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Christoph Hellwigc988afb2010-02-16 03:44:50 -050025static int check_quotactl_permission(struct super_block *sb, int type, int cmd,
26 qid_t id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
Christoph Hellwigc988afb2010-02-16 03:44:50 -050028 switch (cmd) {
29 /* these commands do not require any special privilegues */
30 case Q_GETFMT:
31 case Q_SYNC:
32 case Q_GETINFO:
33 case Q_XGETQSTAT:
34 case Q_XQUOTASYNC:
35 break;
36 /* allow to query information for dquots we "own" */
37 case Q_GETQUOTA:
38 case Q_XGETQUOTA:
39 if ((type == USRQUOTA && current_euid() == id) ||
40 (type == GRPQUOTA && in_egroup_p(id)))
41 break;
42 /*FALLTHROUGH*/
43 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 if (!capable(CAP_SYS_ADMIN))
45 return -EPERM;
46 }
47
Christoph Hellwigc988afb2010-02-16 03:44:50 -050048 return security_quotactl(cmd, type, id, sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
Christoph Hellwig6ae09572010-02-16 03:44:49 -050051static int quota_sync_all(int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Christoph Hellwig850b2012009-04-27 16:43:54 +020053 struct super_block *sb;
Jan Kara02a55ca2008-07-25 01:46:50 -070054 int cnt;
Christoph Hellwig6ae09572010-02-16 03:44:49 -050055 int ret;
56
57 if (type >= MAXQUOTAS)
58 return -EINVAL;
59 ret = security_quotactl(Q_SYNC, type, 0, NULL);
60 if (ret)
61 return ret;
Kirill Korotaev618f0632005-06-23 00:09:54 -070062
Kirill Korotaev618f0632005-06-23 00:09:54 -070063 spin_lock(&sb_lock);
64restart:
65 list_for_each_entry(sb, &super_blocks, s_list) {
Christoph Hellwig5fb324a2010-02-16 03:44:52 -050066 if (!sb->s_qcop || !sb->s_qcop->quota_sync)
67 continue;
68
Jan Kara268157b2009-01-27 15:47:22 +010069 /* This test just improves performance so it needn't be
70 * reliable... */
Jan Kara02a55ca2008-07-25 01:46:50 -070071 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
72 if (type != -1 && type != cnt)
73 continue;
Jan Karaf55abc02008-08-20 17:50:32 +020074 if (!sb_has_quota_active(sb, cnt))
Jan Kara02a55ca2008-07-25 01:46:50 -070075 continue;
76 if (!info_dirty(&sb_dqopt(sb)->info[cnt]) &&
Jan Kara268157b2009-01-27 15:47:22 +010077 list_empty(&sb_dqopt(sb)->info[cnt].dqi_dirty_list))
Jan Kara02a55ca2008-07-25 01:46:50 -070078 continue;
79 break;
80 }
81 if (cnt == MAXQUOTAS)
Kirill Korotaev618f0632005-06-23 00:09:54 -070082 continue;
83 sb->s_count++;
84 spin_unlock(&sb_lock);
85 down_read(&sb->s_umount);
Christoph Hellwig850b2012009-04-27 16:43:54 +020086 if (sb->s_root)
Christoph Hellwig5fb324a2010-02-16 03:44:52 -050087 sb->s_qcop->quota_sync(sb, type, 1);
Kirill Korotaev618f0632005-06-23 00:09:54 -070088 up_read(&sb->s_umount);
89 spin_lock(&sb_lock);
90 if (__put_super_and_need_restart(sb))
91 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 }
Kirill Korotaev618f0632005-06-23 00:09:54 -070093 spin_unlock(&sb_lock);
Christoph Hellwig6ae09572010-02-16 03:44:49 -050094
95 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}
97
Christoph Hellwigc411e5f2010-02-16 03:44:47 -050098static int quota_quotaon(struct super_block *sb, int type, int cmd, qid_t id,
99 void __user *addr)
100{
101 char *pathname;
Christoph Hellwigf450d4f2010-02-16 03:44:48 -0500102 int ret = -ENOSYS;
Christoph Hellwigc411e5f2010-02-16 03:44:47 -0500103
104 pathname = getname(addr);
105 if (IS_ERR(pathname))
106 return PTR_ERR(pathname);
Christoph Hellwigf450d4f2010-02-16 03:44:48 -0500107 if (sb->s_qcop->quota_on)
108 ret = sb->s_qcop->quota_on(sb, type, id, pathname, 0);
Christoph Hellwigc411e5f2010-02-16 03:44:47 -0500109 putname(pathname);
110 return ret;
111}
112
113static int quota_getfmt(struct super_block *sb, int type, void __user *addr)
114{
115 __u32 fmt;
116
117 down_read(&sb_dqopt(sb)->dqptr_sem);
118 if (!sb_has_quota_active(sb, type)) {
119 up_read(&sb_dqopt(sb)->dqptr_sem);
120 return -ESRCH;
121 }
122 fmt = sb_dqopt(sb)->info[type].dqi_format->qf_fmt_id;
123 up_read(&sb_dqopt(sb)->dqptr_sem);
124 if (copy_to_user(addr, &fmt, sizeof(fmt)))
125 return -EFAULT;
126 return 0;
127}
128
129static int quota_getinfo(struct super_block *sb, int type, void __user *addr)
130{
131 struct if_dqinfo info;
132 int ret;
133
Christoph Hellwigf450d4f2010-02-16 03:44:48 -0500134 if (!sb_has_quota_active(sb, type))
135 return -ESRCH;
136 if (!sb->s_qcop->get_info)
137 return -ENOSYS;
Christoph Hellwigc411e5f2010-02-16 03:44:47 -0500138 ret = sb->s_qcop->get_info(sb, type, &info);
139 if (!ret && copy_to_user(addr, &info, sizeof(info)))
140 return -EFAULT;
141 return ret;
142}
143
144static int quota_setinfo(struct super_block *sb, int type, void __user *addr)
145{
146 struct if_dqinfo info;
147
148 if (copy_from_user(&info, addr, sizeof(info)))
149 return -EFAULT;
Christoph Hellwigf450d4f2010-02-16 03:44:48 -0500150 if (!sb_has_quota_active(sb, type))
151 return -ESRCH;
152 if (!sb->s_qcop->set_info)
153 return -ENOSYS;
Christoph Hellwigc411e5f2010-02-16 03:44:47 -0500154 return sb->s_qcop->set_info(sb, type, &info);
155}
156
157static int quota_getquota(struct super_block *sb, int type, qid_t id,
158 void __user *addr)
159{
160 struct if_dqblk idq;
161 int ret;
162
Christoph Hellwigf450d4f2010-02-16 03:44:48 -0500163 if (!sb_has_quota_active(sb, type))
164 return -ESRCH;
165 if (!sb->s_qcop->get_dqblk)
166 return -ENOSYS;
Christoph Hellwigc411e5f2010-02-16 03:44:47 -0500167 ret = sb->s_qcop->get_dqblk(sb, type, id, &idq);
168 if (ret)
169 return ret;
170 if (copy_to_user(addr, &idq, sizeof(idq)))
171 return -EFAULT;
172 return 0;
173}
174
175static int quota_setquota(struct super_block *sb, int type, qid_t id,
176 void __user *addr)
177{
178 struct if_dqblk idq;
179
180 if (copy_from_user(&idq, addr, sizeof(idq)))
181 return -EFAULT;
Christoph Hellwigf450d4f2010-02-16 03:44:48 -0500182 if (!sb_has_quota_active(sb, type))
183 return -ESRCH;
184 if (!sb->s_qcop->set_dqblk)
185 return -ENOSYS;
Christoph Hellwigc411e5f2010-02-16 03:44:47 -0500186 return sb->s_qcop->set_dqblk(sb, type, id, &idq);
187}
188
189static int quota_setxstate(struct super_block *sb, int cmd, void __user *addr)
190{
191 __u32 flags;
192
193 if (copy_from_user(&flags, addr, sizeof(flags)))
194 return -EFAULT;
Christoph Hellwigf450d4f2010-02-16 03:44:48 -0500195 if (!sb->s_qcop->set_xstate)
196 return -ENOSYS;
Christoph Hellwigc411e5f2010-02-16 03:44:47 -0500197 return sb->s_qcop->set_xstate(sb, flags, cmd);
198}
199
200static int quota_getxstate(struct super_block *sb, void __user *addr)
201{
202 struct fs_quota_stat fqs;
203 int ret;
Christoph Hellwigf450d4f2010-02-16 03:44:48 -0500204
205 if (!sb->s_qcop->get_xstate)
206 return -ENOSYS;
Christoph Hellwigc411e5f2010-02-16 03:44:47 -0500207 ret = sb->s_qcop->get_xstate(sb, &fqs);
208 if (!ret && copy_to_user(addr, &fqs, sizeof(fqs)))
209 return -EFAULT;
210 return ret;
211}
212
213static int quota_setxquota(struct super_block *sb, int type, qid_t id,
214 void __user *addr)
215{
216 struct fs_disk_quota fdq;
217
218 if (copy_from_user(&fdq, addr, sizeof(fdq)))
219 return -EFAULT;
Christoph Hellwigf450d4f2010-02-16 03:44:48 -0500220 if (!sb->s_qcop->set_xquota)
221 return -ENOSYS;
Christoph Hellwigc411e5f2010-02-16 03:44:47 -0500222 return sb->s_qcop->set_xquota(sb, type, id, &fdq);
223}
224
225static int quota_getxquota(struct super_block *sb, int type, qid_t id,
226 void __user *addr)
227{
228 struct fs_disk_quota fdq;
229 int ret;
230
Christoph Hellwigf450d4f2010-02-16 03:44:48 -0500231 if (!sb->s_qcop->get_xquota)
232 return -ENOSYS;
Christoph Hellwigc411e5f2010-02-16 03:44:47 -0500233 ret = sb->s_qcop->get_xquota(sb, type, id, &fdq);
234 if (!ret && copy_to_user(addr, &fdq, sizeof(fdq)))
235 return -EFAULT;
236 return ret;
237}
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239/* Copy parameters and call proper function */
Jan Kara268157b2009-01-27 15:47:22 +0100240static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
241 void __user *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Christoph Hellwigc988afb2010-02-16 03:44:50 -0500243 int ret;
244
245 if (type >= (XQM_COMMAND(cmd) ? XQM_MAXQUOTAS : MAXQUOTAS))
246 return -EINVAL;
247 if (!sb->s_qcop)
248 return -ENOSYS;
249
250 ret = check_quotactl_permission(sb, type, cmd, id);
251 if (ret < 0)
252 return ret;
253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 switch (cmd) {
Christoph Hellwigc411e5f2010-02-16 03:44:47 -0500255 case Q_QUOTAON:
256 return quota_quotaon(sb, type, cmd, id, addr);
257 case Q_QUOTAOFF:
Christoph Hellwigf450d4f2010-02-16 03:44:48 -0500258 if (!sb->s_qcop->quota_off)
259 return -ENOSYS;
Christoph Hellwigc411e5f2010-02-16 03:44:47 -0500260 return sb->s_qcop->quota_off(sb, type, 0);
261 case Q_GETFMT:
262 return quota_getfmt(sb, type, addr);
263 case Q_GETINFO:
264 return quota_getinfo(sb, type, addr);
265 case Q_SETINFO:
266 return quota_setinfo(sb, type, addr);
267 case Q_GETQUOTA:
268 return quota_getquota(sb, type, id, addr);
269 case Q_SETQUOTA:
270 return quota_setquota(sb, type, id, addr);
271 case Q_SYNC:
Christoph Hellwig6ae09572010-02-16 03:44:49 -0500272 if (!sb->s_qcop->quota_sync)
273 return -ENOSYS;
Christoph Hellwig5fb324a2010-02-16 03:44:52 -0500274 return sb->s_qcop->quota_sync(sb, type, 1);
Christoph Hellwigc411e5f2010-02-16 03:44:47 -0500275 case Q_XQUOTAON:
276 case Q_XQUOTAOFF:
277 case Q_XQUOTARM:
278 return quota_setxstate(sb, cmd, addr);
279 case Q_XGETQSTAT:
280 return quota_getxstate(sb, addr);
281 case Q_XSETQLIM:
282 return quota_setxquota(sb, type, id, addr);
283 case Q_XGETQUOTA:
284 return quota_getxquota(sb, type, id, addr);
285 case Q_XQUOTASYNC:
Christoph Hellwig8c4e4ac2010-02-16 03:44:51 -0500286 /* caller already holds s_umount */
287 if (sb->s_flags & MS_RDONLY)
288 return -EROFS;
289 writeback_inodes_sb(sb);
290 return 0;
Christoph Hellwigc411e5f2010-02-16 03:44:47 -0500291 default:
Christoph Hellwigf450d4f2010-02-16 03:44:48 -0500292 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294}
295
296/*
David Howells93614012006-09-30 20:45:40 +0200297 * look up a superblock on which quota ops will be performed
298 * - use the name of a block device to find the superblock thereon
299 */
Jan Kara7a2435d2009-01-27 01:47:11 +0100300static struct super_block *quotactl_block(const char __user *special)
David Howells93614012006-09-30 20:45:40 +0200301{
302#ifdef CONFIG_BLOCK
303 struct block_device *bdev;
304 struct super_block *sb;
305 char *tmp = getname(special);
306
307 if (IS_ERR(tmp))
David Howellse231c2e2008-02-07 00:15:26 -0800308 return ERR_CAST(tmp);
David Howells93614012006-09-30 20:45:40 +0200309 bdev = lookup_bdev(tmp);
310 putname(tmp);
311 if (IS_ERR(bdev))
David Howellse231c2e2008-02-07 00:15:26 -0800312 return ERR_CAST(bdev);
David Howells93614012006-09-30 20:45:40 +0200313 sb = get_super(bdev);
314 bdput(bdev);
315 if (!sb)
316 return ERR_PTR(-ENODEV);
317
318 return sb;
319#else
320 return ERR_PTR(-ENODEV);
321#endif
322}
323
324/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 * This is the system call interface. This communicates with
326 * the user-level programs. Currently this only supports diskquota
327 * calls. Maybe we need to add the process quotas etc. in the future,
328 * but we probably should use rlimits for that.
329 */
Heiko Carstens3cdad422009-01-14 14:14:22 +0100330SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,
331 qid_t, id, void __user *, addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
333 uint cmds, type;
334 struct super_block *sb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 int ret;
336
337 cmds = cmd >> SUBCMDSHIFT;
338 type = cmd & SUBCMDMASK;
339
Christoph Hellwig6ae09572010-02-16 03:44:49 -0500340 /*
341 * As a special case Q_SYNC can be called without a specific device.
342 * It will iterate all superblocks that have quota enabled and call
343 * the sync action on each of them.
344 */
345 if (!special) {
346 if (cmds == Q_SYNC)
347 return quota_sync_all(type);
348 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
350
Christoph Hellwig6ae09572010-02-16 03:44:49 -0500351 sb = quotactl_block(special);
352 if (IS_ERR(sb))
353 return PTR_ERR(sb);
354
Christoph Hellwigc988afb2010-02-16 03:44:50 -0500355 ret = do_quotactl(sb, type, cmds, id, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Christoph Hellwig6ae09572010-02-16 03:44:49 -0500357 drop_super(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 return ret;
359}
Vasily Tarasovb7163952007-07-15 23:41:12 -0700360
Tony Luck7a6c8132007-07-27 15:35:43 -0700361#if defined(CONFIG_COMPAT_FOR_U64_ALIGNMENT)
Vasily Tarasovb7163952007-07-15 23:41:12 -0700362/*
363 * This code works only for 32 bit quota tools over 64 bit OS (x86_64, ia64)
364 * and is necessary due to alignment problems.
365 */
366struct compat_if_dqblk {
367 compat_u64 dqb_bhardlimit;
368 compat_u64 dqb_bsoftlimit;
369 compat_u64 dqb_curspace;
370 compat_u64 dqb_ihardlimit;
371 compat_u64 dqb_isoftlimit;
372 compat_u64 dqb_curinodes;
373 compat_u64 dqb_btime;
374 compat_u64 dqb_itime;
375 compat_uint_t dqb_valid;
376};
377
378/* XFS structures */
379struct compat_fs_qfilestat {
380 compat_u64 dqb_bhardlimit;
381 compat_u64 qfs_nblks;
382 compat_uint_t qfs_nextents;
383};
384
385struct compat_fs_quota_stat {
386 __s8 qs_version;
387 __u16 qs_flags;
388 __s8 qs_pad;
389 struct compat_fs_qfilestat qs_uquota;
390 struct compat_fs_qfilestat qs_gquota;
391 compat_uint_t qs_incoredqs;
392 compat_int_t qs_btimelimit;
393 compat_int_t qs_itimelimit;
394 compat_int_t qs_rtbtimelimit;
395 __u16 qs_bwarnlimit;
396 __u16 qs_iwarnlimit;
397};
398
399asmlinkage long sys32_quotactl(unsigned int cmd, const char __user *special,
400 qid_t id, void __user *addr)
401{
402 unsigned int cmds;
403 struct if_dqblk __user *dqblk;
404 struct compat_if_dqblk __user *compat_dqblk;
405 struct fs_quota_stat __user *fsqstat;
406 struct compat_fs_quota_stat __user *compat_fsqstat;
407 compat_uint_t data;
408 u16 xdata;
409 long ret;
410
411 cmds = cmd >> SUBCMDSHIFT;
412
413 switch (cmds) {
414 case Q_GETQUOTA:
415 dqblk = compat_alloc_user_space(sizeof(struct if_dqblk));
416 compat_dqblk = addr;
417 ret = sys_quotactl(cmd, special, id, dqblk);
418 if (ret)
419 break;
420 if (copy_in_user(compat_dqblk, dqblk, sizeof(*compat_dqblk)) ||
421 get_user(data, &dqblk->dqb_valid) ||
422 put_user(data, &compat_dqblk->dqb_valid))
423 ret = -EFAULT;
424 break;
425 case Q_SETQUOTA:
426 dqblk = compat_alloc_user_space(sizeof(struct if_dqblk));
427 compat_dqblk = addr;
428 ret = -EFAULT;
429 if (copy_in_user(dqblk, compat_dqblk, sizeof(*compat_dqblk)) ||
430 get_user(data, &compat_dqblk->dqb_valid) ||
431 put_user(data, &dqblk->dqb_valid))
432 break;
433 ret = sys_quotactl(cmd, special, id, dqblk);
434 break;
435 case Q_XGETQSTAT:
436 fsqstat = compat_alloc_user_space(sizeof(struct fs_quota_stat));
437 compat_fsqstat = addr;
438 ret = sys_quotactl(cmd, special, id, fsqstat);
439 if (ret)
440 break;
441 ret = -EFAULT;
442 /* Copying qs_version, qs_flags, qs_pad */
443 if (copy_in_user(compat_fsqstat, fsqstat,
444 offsetof(struct compat_fs_quota_stat, qs_uquota)))
445 break;
446 /* Copying qs_uquota */
447 if (copy_in_user(&compat_fsqstat->qs_uquota,
448 &fsqstat->qs_uquota,
449 sizeof(compat_fsqstat->qs_uquota)) ||
450 get_user(data, &fsqstat->qs_uquota.qfs_nextents) ||
451 put_user(data, &compat_fsqstat->qs_uquota.qfs_nextents))
452 break;
453 /* Copying qs_gquota */
454 if (copy_in_user(&compat_fsqstat->qs_gquota,
455 &fsqstat->qs_gquota,
456 sizeof(compat_fsqstat->qs_gquota)) ||
457 get_user(data, &fsqstat->qs_gquota.qfs_nextents) ||
458 put_user(data, &compat_fsqstat->qs_gquota.qfs_nextents))
459 break;
460 /* Copying the rest */
461 if (copy_in_user(&compat_fsqstat->qs_incoredqs,
462 &fsqstat->qs_incoredqs,
463 sizeof(struct compat_fs_quota_stat) -
464 offsetof(struct compat_fs_quota_stat, qs_incoredqs)) ||
465 get_user(xdata, &fsqstat->qs_iwarnlimit) ||
466 put_user(xdata, &compat_fsqstat->qs_iwarnlimit))
467 break;
468 ret = 0;
469 break;
470 default:
471 ret = sys_quotactl(cmd, special, id, addr);
472 }
473 return ret;
474}
475#endif
Steven Whitehouse86e931a2009-09-28 12:35:17 +0100476
477
478#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
479
480/* Netlink family structure for quota */
481static struct genl_family quota_genl_family = {
482 .id = GENL_ID_GENERATE,
483 .hdrsize = 0,
484 .name = "VFS_DQUOT",
485 .version = 1,
486 .maxattr = QUOTA_NL_A_MAX,
487};
488
489/**
490 * quota_send_warning - Send warning to userspace about exceeded quota
491 * @type: The quota type: USRQQUOTA, GRPQUOTA,...
492 * @id: The user or group id of the quota that was exceeded
493 * @dev: The device on which the fs is mounted (sb->s_dev)
494 * @warntype: The type of the warning: QUOTA_NL_...
495 *
496 * This can be used by filesystems (including those which don't use
497 * dquot) to send a message to userspace relating to quota limits.
498 *
499 */
500
501void quota_send_warning(short type, unsigned int id, dev_t dev,
502 const char warntype)
503{
504 static atomic_t seq;
505 struct sk_buff *skb;
506 void *msg_head;
507 int ret;
508 int msg_size = 4 * nla_total_size(sizeof(u32)) +
509 2 * nla_total_size(sizeof(u64));
510
511 /* We have to allocate using GFP_NOFS as we are called from a
512 * filesystem performing write and thus further recursion into
513 * the fs to free some data could cause deadlocks. */
514 skb = genlmsg_new(msg_size, GFP_NOFS);
515 if (!skb) {
516 printk(KERN_ERR
517 "VFS: Not enough memory to send quota warning.\n");
518 return;
519 }
520 msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
521 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
522 if (!msg_head) {
523 printk(KERN_ERR
524 "VFS: Cannot store netlink header in quota warning.\n");
525 goto err_out;
526 }
527 ret = nla_put_u32(skb, QUOTA_NL_A_QTYPE, type);
528 if (ret)
529 goto attr_err_out;
530 ret = nla_put_u64(skb, QUOTA_NL_A_EXCESS_ID, id);
531 if (ret)
532 goto attr_err_out;
533 ret = nla_put_u32(skb, QUOTA_NL_A_WARNING, warntype);
534 if (ret)
535 goto attr_err_out;
536 ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MAJOR, MAJOR(dev));
537 if (ret)
538 goto attr_err_out;
539 ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MINOR, MINOR(dev));
540 if (ret)
541 goto attr_err_out;
542 ret = nla_put_u64(skb, QUOTA_NL_A_CAUSED_ID, current_uid());
543 if (ret)
544 goto attr_err_out;
545 genlmsg_end(skb, msg_head);
546
547 genlmsg_multicast(skb, 0, quota_genl_family.id, GFP_NOFS);
548 return;
549attr_err_out:
550 printk(KERN_ERR "VFS: Not enough space to compose quota message!\n");
551err_out:
552 kfree_skb(skb);
553}
554EXPORT_SYMBOL(quota_send_warning);
555
556static int __init quota_init(void)
557{
558 if (genl_register_family(&quota_genl_family) != 0)
559 printk(KERN_ERR
560 "VFS: Failed to create quota netlink interface.\n");
561 return 0;
562};
563
564module_init(quota_init);
565#endif
566