mqueue.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. /*
  2. * POSIX message queues filesystem for Linux.
  3. *
  4. * Copyright (C) 2003,2004 Krzysztof Benedyczak (golbi@mat.uni.torun.pl)
  5. * Michal Wronski (michal.wronski@gmail.com)
  6. *
  7. * Spinlocks: Mohamed Abbas (abbas.mohamed@intel.com)
  8. * Lockless receive & send, fd based notify:
  9. * Manfred Spraul (manfred@colorfullife.com)
  10. *
  11. * Audit: George Wilson (ltcgcw@us.ibm.com)
  12. *
  13. * This file is released under the GPL.
  14. */
  15. #include <linux/capability.h>
  16. #include <linux/init.h>
  17. #include <linux/pagemap.h>
  18. #include <linux/file.h>
  19. #include <linux/mount.h>
  20. #include <linux/namei.h>
  21. #include <linux/sysctl.h>
  22. #include <linux/poll.h>
  23. #include <linux/mqueue.h>
  24. #include <linux/msg.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/netlink.h>
  27. #include <linux/syscalls.h>
  28. #include <linux/audit.h>
  29. #include <linux/signal.h>
  30. #include <linux/mutex.h>
  31. #include <linux/nsproxy.h>
  32. #include <linux/pid.h>
  33. #include <linux/ipc_namespace.h>
  34. #include <linux/slab.h>
  35. #include <net/sock.h>
  36. #include "util.h"
  37. #define MQUEUE_MAGIC 0x19800202
  38. #define DIRENT_SIZE 20
  39. #define FILENT_SIZE 80
  40. #define SEND 0
  41. #define RECV 1
  42. #define STATE_NONE 0
  43. #define STATE_PENDING 1
  44. #define STATE_READY 2
  45. struct ext_wait_queue { /* queue of sleeping tasks */
  46. struct task_struct *task;
  47. struct list_head list;
  48. struct msg_msg *msg; /* ptr of loaded message */
  49. int state; /* one of STATE_* values */
  50. };
  51. struct mqueue_inode_info {
  52. spinlock_t lock;
  53. struct inode vfs_inode;
  54. wait_queue_head_t wait_q;
  55. struct msg_msg **messages;
  56. struct mq_attr attr;
  57. struct sigevent notify;
  58. struct pid* notify_owner;
  59. struct user_struct *user; /* user who created, for accounting */
  60. struct sock *notify_sock;
  61. struct sk_buff *notify_cookie;
  62. /* for tasks waiting for free space and messages, respectively */
  63. struct ext_wait_queue e_wait_q[2];
  64. unsigned long qsize; /* size of queue in memory (sum of all msgs) */
  65. };
  66. static const struct inode_operations mqueue_dir_inode_operations;
  67. static const struct file_operations mqueue_file_operations;
  68. static const struct super_operations mqueue_super_ops;
  69. static void remove_notification(struct mqueue_inode_info *info);
  70. static struct kmem_cache *mqueue_inode_cachep;
  71. static struct ctl_table_header * mq_sysctl_table;
  72. static inline struct mqueue_inode_info *MQUEUE_I(struct inode *inode)
  73. {
  74. return container_of(inode, struct mqueue_inode_info, vfs_inode);
  75. }
  76. /*
  77. * This routine should be called with the mq_lock held.
  78. */
  79. static inline struct ipc_namespace *__get_ns_from_inode(struct inode *inode)
  80. {
  81. return get_ipc_ns(inode->i_sb->s_fs_info);
  82. }
  83. static struct ipc_namespace *get_ns_from_inode(struct inode *inode)
  84. {
  85. struct ipc_namespace *ns;
  86. spin_lock(&mq_lock);
  87. ns = __get_ns_from_inode(inode);
  88. spin_unlock(&mq_lock);
  89. return ns;
  90. }
  91. static struct inode *mqueue_get_inode(struct super_block *sb,
  92. struct ipc_namespace *ipc_ns, int mode,
  93. struct mq_attr *attr)
  94. {
  95. struct user_struct *u = current_user();
  96. struct inode *inode;
  97. int ret = -ENOMEM;
  98. inode = new_inode(sb);
  99. if (!inode)
  100. goto err;
  101. inode->i_ino = get_next_ino();
  102. inode->i_mode = mode;
  103. inode->i_uid = current_fsuid();
  104. inode->i_gid = current_fsgid();
  105. inode->i_mtime = inode->i_ctime = inode->i_atime = CURRENT_TIME;
  106. if (S_ISREG(mode)) {
  107. struct mqueue_inode_info *info;
  108. struct task_struct *p = current;
  109. unsigned long mq_bytes, mq_msg_tblsz;
  110. inode->i_fop = &mqueue_file_operations;
  111. inode->i_size = FILENT_SIZE;
  112. /* mqueue specific info */
  113. info = MQUEUE_I(inode);
  114. spin_lock_init(&info->lock);
  115. init_waitqueue_head(&info->wait_q);
  116. INIT_LIST_HEAD(&info->e_wait_q[0].list);
  117. INIT_LIST_HEAD(&info->e_wait_q[1].list);
  118. info->notify_owner = NULL;
  119. info->qsize = 0;
  120. info->user = NULL; /* set when all is ok */
  121. memset(&info->attr, 0, sizeof(info->attr));
  122. info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
  123. info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
  124. if (attr) {
  125. info->attr.mq_maxmsg = attr->mq_maxmsg;
  126. info->attr.mq_msgsize = attr->mq_msgsize;
  127. }
  128. mq_msg_tblsz = info->attr.mq_maxmsg * sizeof(struct msg_msg *);
  129. info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
  130. if (!info->messages)
  131. goto out_inode;
  132. mq_bytes = (mq_msg_tblsz +
  133. (info->attr.mq_maxmsg * info->attr.mq_msgsize));
  134. spin_lock(&mq_lock);
  135. if (u->mq_bytes + mq_bytes < u->mq_bytes ||
  136. u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
  137. spin_unlock(&mq_lock);
  138. /* mqueue_evict_inode() releases info->messages */
  139. ret = -EMFILE;
  140. goto out_inode;
  141. }
  142. u->mq_bytes += mq_bytes;
  143. spin_unlock(&mq_lock);
  144. /* all is ok */
  145. info->user = get_uid(u);
  146. } else if (S_ISDIR(mode)) {
  147. inc_nlink(inode);
  148. /* Some things misbehave if size == 0 on a directory */
  149. inode->i_size = 2 * DIRENT_SIZE;
  150. inode->i_op = &mqueue_dir_inode_operations;
  151. inode->i_fop = &simple_dir_operations;
  152. }
  153. return inode;
  154. out_inode:
  155. iput(inode);
  156. err:
  157. return ERR_PTR(ret);
  158. }
  159. static int mqueue_fill_super(struct super_block *sb, void *data, int silent)
  160. {
  161. struct inode *inode;
  162. struct ipc_namespace *ns = data;
  163. int error;
  164. sb->s_blocksize = PAGE_CACHE_SIZE;
  165. sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
  166. sb->s_magic = MQUEUE_MAGIC;
  167. sb->s_op = &mqueue_super_ops;
  168. inode = mqueue_get_inode(sb, ns, S_IFDIR | S_ISVTX | S_IRWXUGO,
  169. NULL);
  170. if (IS_ERR(inode)) {
  171. error = PTR_ERR(inode);
  172. goto out;
  173. }
  174. sb->s_root = d_alloc_root(inode);
  175. if (!sb->s_root) {
  176. iput(inode);
  177. error = -ENOMEM;
  178. goto out;
  179. }
  180. error = 0;
  181. out:
  182. return error;
  183. }
  184. static struct dentry *mqueue_mount(struct file_system_type *fs_type,
  185. int flags, const char *dev_name,
  186. void *data)
  187. {
  188. if (!(flags & MS_KERNMOUNT))
  189. data = current->nsproxy->ipc_ns;
  190. return mount_ns(fs_type, flags, data, mqueue_fill_super);
  191. }
  192. static void init_once(void *foo)
  193. {
  194. struct mqueue_inode_info *p = (struct mqueue_inode_info *) foo;
  195. inode_init_once(&p->vfs_inode);
  196. }
  197. static struct inode *mqueue_alloc_inode(struct super_block *sb)
  198. {
  199. struct mqueue_inode_info *ei;
  200. ei = kmem_cache_alloc(mqueue_inode_cachep, GFP_KERNEL);
  201. if (!ei)
  202. return NULL;
  203. return &ei->vfs_inode;
  204. }
  205. static void mqueue_i_callback(struct rcu_head *head)
  206. {
  207. struct inode *inode = container_of(head, struct inode, i_rcu);
  208. INIT_LIST_HEAD(&inode->i_dentry);
  209. kmem_cache_free(mqueue_inode_cachep, MQUEUE_I(inode));
  210. }
  211. static void mqueue_destroy_inode(struct inode *inode)
  212. {
  213. call_rcu(&inode->i_rcu, mqueue_i_callback);
  214. }
  215. static void mqueue_evict_inode(struct inode *inode)
  216. {
  217. struct mqueue_inode_info *info;
  218. struct user_struct *user;
  219. unsigned long mq_bytes;
  220. int i;
  221. struct ipc_namespace *ipc_ns;
  222. end_writeback(inode);
  223. if (S_ISDIR(inode->i_mode))
  224. return;
  225. ipc_ns = get_ns_from_inode(inode);
  226. info = MQUEUE_I(inode);
  227. spin_lock(&info->lock);
  228. for (i = 0; i < info->attr.mq_curmsgs; i++)
  229. free_msg(info->messages[i]);
  230. kfree(info->messages);
  231. spin_unlock(&info->lock);
  232. /* Total amount of bytes accounted for the mqueue */
  233. mq_bytes = info->attr.mq_maxmsg * (sizeof(struct msg_msg *)
  234. + info->attr.mq_msgsize);
  235. user = info->user;
  236. if (user) {
  237. spin_lock(&mq_lock);
  238. user->mq_bytes -= mq_bytes;
  239. /*
  240. * get_ns_from_inode() ensures that the
  241. * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
  242. * to which we now hold a reference, or it is NULL.
  243. * We can't put it here under mq_lock, though.
  244. */
  245. if (ipc_ns)
  246. ipc_ns->mq_queues_count--;
  247. spin_unlock(&mq_lock);
  248. free_uid(user);
  249. }
  250. if (ipc_ns)
  251. put_ipc_ns(ipc_ns);
  252. }
  253. static int mqueue_create(struct inode *dir, struct dentry *dentry,
  254. int mode, struct nameidata *nd)
  255. {
  256. struct inode *inode;
  257. struct mq_attr *attr = dentry->d_fsdata;
  258. int error;
  259. struct ipc_namespace *ipc_ns;
  260. spin_lock(&mq_lock);
  261. ipc_ns = __get_ns_from_inode(dir);
  262. if (!ipc_ns) {
  263. error = -EACCES;
  264. goto out_unlock;
  265. }
  266. if (ipc_ns->mq_queues_count >= ipc_ns->mq_queues_max &&
  267. !capable(CAP_SYS_RESOURCE)) {
  268. error = -ENOSPC;
  269. goto out_unlock;
  270. }
  271. ipc_ns->mq_queues_count++;
  272. spin_unlock(&mq_lock);
  273. inode = mqueue_get_inode(dir->i_sb, ipc_ns, mode, attr);
  274. if (IS_ERR(inode)) {
  275. error = PTR_ERR(inode);
  276. spin_lock(&mq_lock);
  277. ipc_ns->mq_queues_count--;
  278. goto out_unlock;
  279. }
  280. put_ipc_ns(ipc_ns);
  281. dir->i_size += DIRENT_SIZE;
  282. dir->i_ctime = dir->i_mtime = dir->i_atime = CURRENT_TIME;
  283. d_instantiate(dentry, inode);
  284. dget(dentry);
  285. return 0;
  286. out_unlock:
  287. spin_unlock(&mq_lock);
  288. if (ipc_ns)
  289. put_ipc_ns(ipc_ns);
  290. return error;
  291. }
  292. static int mqueue_unlink(struct inode *dir, struct dentry *dentry)
  293. {
  294. struct inode *inode = dentry->d_inode;
  295. dir->i_ctime = dir->i_mtime = dir->i_atime = CURRENT_TIME;
  296. dir->i_size -= DIRENT_SIZE;
  297. drop_nlink(inode);
  298. dput(dentry);
  299. return 0;
  300. }
  301. /*
  302. * This is routine for system read from queue file.
  303. * To avoid mess with doing here some sort of mq_receive we allow
  304. * to read only queue size & notification info (the only values
  305. * that are interesting from user point of view and aren't accessible
  306. * through std routines)
  307. */
  308. static ssize_t mqueue_read_file(struct file *filp, char __user *u_data,
  309. size_t count, loff_t *off)
  310. {
  311. struct mqueue_inode_info *info = MQUEUE_I(filp->f_path.dentry->d_inode);
  312. char buffer[FILENT_SIZE];
  313. ssize_t ret;
  314. spin_lock(&info->lock);
  315. snprintf(buffer, sizeof(buffer),
  316. "QSIZE:%-10lu NOTIFY:%-5d SIGNO:%-5d NOTIFY_PID:%-6d\n",
  317. info->qsize,
  318. info->notify_owner ? info->notify.sigev_notify : 0,
  319. (info->notify_owner &&
  320. info->notify.sigev_notify == SIGEV_SIGNAL) ?
  321. info->notify.sigev_signo : 0,
  322. pid_vnr(info->notify_owner));
  323. spin_unlock(&info->lock);
  324. buffer[sizeof(buffer)-1] = '\0';
  325. ret = simple_read_from_buffer(u_data, count, off, buffer,
  326. strlen(buffer));
  327. if (ret <= 0)
  328. return ret;
  329. filp->f_path.dentry->d_inode->i_atime = filp->f_path.dentry->d_inode->i_ctime = CURRENT_TIME;
  330. return ret;
  331. }
  332. static int mqueue_flush_file(struct file *filp, fl_owner_t id)
  333. {
  334. struct mqueue_inode_info *info = MQUEUE_I(filp->f_path.dentry->d_inode);
  335. spin_lock(&info->lock);
  336. if (task_tgid(current) == info->notify_owner)
  337. remove_notification(info);
  338. spin_unlock(&info->lock);
  339. return 0;
  340. }
  341. static unsigned int mqueue_poll_file(struct file *filp, struct poll_table_struct *poll_tab)
  342. {
  343. struct mqueue_inode_info *info = MQUEUE_I(filp->f_path.dentry->d_inode);
  344. int retval = 0;
  345. poll_wait(filp, &info->wait_q, poll_tab);
  346. spin_lock(&info->lock);
  347. if (info->attr.mq_curmsgs)
  348. retval = POLLIN | POLLRDNORM;
  349. if (info->attr.mq_curmsgs < info->attr.mq_maxmsg)
  350. retval |= POLLOUT | POLLWRNORM;
  351. spin_unlock(&info->lock);
  352. return retval;
  353. }
  354. /* Adds current to info->e_wait_q[sr] before element with smaller prio */
  355. static void wq_add(struct mqueue_inode_info *info, int sr,
  356. struct ext_wait_queue *ewp)
  357. {
  358. struct ext_wait_queue *walk;
  359. ewp->task = current;
  360. list_for_each_entry(walk, &info->e_wait_q[sr].list, list) {
  361. if (walk->task->static_prio <= current->static_prio) {
  362. list_add_tail(&ewp->list, &walk->list);
  363. return;
  364. }
  365. }
  366. list_add_tail(&ewp->list, &info->e_wait_q[sr].list);
  367. }
  368. /*
  369. * Puts current task to sleep. Caller must hold queue lock. After return
  370. * lock isn't held.
  371. * sr: SEND or RECV
  372. */
  373. static int wq_sleep(struct mqueue_inode_info *info, int sr,
  374. ktime_t *timeout, struct ext_wait_queue *ewp)
  375. {
  376. int retval;
  377. signed long time;
  378. wq_add(info, sr, ewp);
  379. for (;;) {
  380. set_current_state(TASK_INTERRUPTIBLE);
  381. spin_unlock(&info->lock);
  382. time = schedule_hrtimeout_range_clock(timeout,
  383. HRTIMER_MODE_ABS, 0, CLOCK_REALTIME);
  384. while (ewp->state == STATE_PENDING)
  385. cpu_relax();
  386. if (ewp->state == STATE_READY) {
  387. retval = 0;
  388. goto out;
  389. }
  390. spin_lock(&info->lock);
  391. if (ewp->state == STATE_READY) {
  392. retval = 0;
  393. goto out_unlock;
  394. }
  395. if (signal_pending(current)) {
  396. retval = -ERESTARTSYS;
  397. break;
  398. }
  399. if (time == 0) {
  400. retval = -ETIMEDOUT;
  401. break;
  402. }
  403. }
  404. list_del(&ewp->list);
  405. out_unlock:
  406. spin_unlock(&info->lock);
  407. out:
  408. return retval;
  409. }
  410. /*
  411. * Returns waiting task that should be serviced first or NULL if none exists
  412. */
  413. static struct ext_wait_queue *wq_get_first_waiter(
  414. struct mqueue_inode_info *info, int sr)
  415. {
  416. struct list_head *ptr;
  417. ptr = info->e_wait_q[sr].list.prev;
  418. if (ptr == &info->e_wait_q[sr].list)
  419. return NULL;
  420. return list_entry(ptr, struct ext_wait_queue, list);
  421. }
  422. /* Auxiliary functions to manipulate messages' list */
  423. static void msg_insert(struct msg_msg *ptr, struct mqueue_inode_info *info)
  424. {
  425. int k;
  426. k = info->attr.mq_curmsgs - 1;
  427. while (k >= 0 && info->messages[k]->m_type >= ptr->m_type) {
  428. info->messages[k + 1] = info->messages[k];
  429. k--;
  430. }
  431. info->attr.mq_curmsgs++;
  432. info->qsize += ptr->m_ts;
  433. info->messages[k + 1] = ptr;
  434. }
  435. static inline struct msg_msg *msg_get(struct mqueue_inode_info *info)
  436. {
  437. info->qsize -= info->messages[--info->attr.mq_curmsgs]->m_ts;
  438. return info->messages[info->attr.mq_curmsgs];
  439. }
  440. static inline void set_cookie(struct sk_buff *skb, char code)
  441. {
  442. ((char*)skb->data)[NOTIFY_COOKIE_LEN-1] = code;
  443. }
  444. /*
  445. * The next function is only to split too long sys_mq_timedsend
  446. */
  447. static void __do_notify(struct mqueue_inode_info *info)
  448. {
  449. /* notification
  450. * invoked when there is registered process and there isn't process
  451. * waiting synchronously for message AND state of queue changed from
  452. * empty to not empty. Here we are sure that no one is waiting
  453. * synchronously. */
  454. if (info->notify_owner &&
  455. info->attr.mq_curmsgs == 1) {
  456. struct siginfo sig_i;
  457. switch (info->notify.sigev_notify) {
  458. case SIGEV_NONE:
  459. break;
  460. case SIGEV_SIGNAL:
  461. /* sends signal */
  462. sig_i.si_signo = info->notify.sigev_signo;
  463. sig_i.si_errno = 0;
  464. sig_i.si_code = SI_MESGQ;
  465. sig_i.si_value = info->notify.sigev_value;
  466. sig_i.si_pid = task_tgid_nr_ns(current,
  467. ns_of_pid(info->notify_owner));
  468. sig_i.si_uid = current_uid();
  469. kill_pid_info(info->notify.sigev_signo,
  470. &sig_i, info->notify_owner);
  471. break;
  472. case SIGEV_THREAD:
  473. set_cookie(info->notify_cookie, NOTIFY_WOKENUP);
  474. netlink_sendskb(info->notify_sock, info->notify_cookie);
  475. break;
  476. }
  477. /* after notification unregisters process */
  478. put_pid(info->notify_owner);
  479. info->notify_owner = NULL;
  480. }
  481. wake_up(&info->wait_q);
  482. }
  483. static int prepare_timeout(const struct timespec __user *u_abs_timeout,
  484. ktime_t *expires, struct timespec *ts)
  485. {
  486. if (copy_from_user(ts, u_abs_timeout, sizeof(struct timespec)))
  487. return -EFAULT;
  488. if (!timespec_valid(ts))
  489. return -EINVAL;
  490. *expires = timespec_to_ktime(*ts);
  491. return 0;
  492. }
  493. static void remove_notification(struct mqueue_inode_info *info)
  494. {
  495. if (info->notify_owner != NULL &&
  496. info->notify.sigev_notify == SIGEV_THREAD) {
  497. set_cookie(info->notify_cookie, NOTIFY_REMOVED);
  498. netlink_sendskb(info->notify_sock, info->notify_cookie);
  499. }
  500. put_pid(info->notify_owner);
  501. info->notify_owner = NULL;
  502. }
  503. static int mq_attr_ok(struct ipc_namespace *ipc_ns, struct mq_attr *attr)
  504. {
  505. if (attr->mq_maxmsg <= 0 || attr->mq_msgsize <= 0)
  506. return 0;
  507. if (capable(CAP_SYS_RESOURCE)) {
  508. if (attr->mq_maxmsg > HARD_MSGMAX)
  509. return 0;
  510. } else {
  511. if (attr->mq_maxmsg > ipc_ns->mq_msg_max ||
  512. attr->mq_msgsize > ipc_ns->mq_msgsize_max)
  513. return 0;
  514. }
  515. /* check for overflow */
  516. if (attr->mq_msgsize > ULONG_MAX/attr->mq_maxmsg)
  517. return 0;
  518. if ((unsigned long)(attr->mq_maxmsg * (attr->mq_msgsize
  519. + sizeof (struct msg_msg *))) <
  520. (unsigned long)(attr->mq_maxmsg * attr->mq_msgsize))
  521. return 0;
  522. return 1;
  523. }
  524. /*
  525. * Invoked when creating a new queue via sys_mq_open
  526. */
  527. static struct file *do_create(struct ipc_namespace *ipc_ns, struct dentry *dir,
  528. struct dentry *dentry, int oflag, mode_t mode,
  529. struct mq_attr *attr)
  530. {
  531. const struct cred *cred = current_cred();
  532. struct file *result;
  533. int ret;
  534. if (attr) {
  535. if (!mq_attr_ok(ipc_ns, attr)) {
  536. ret = -EINVAL;
  537. goto out;
  538. }
  539. /* store for use during create */
  540. dentry->d_fsdata = attr;
  541. }
  542. mode &= ~current_umask();
  543. ret = mnt_want_write(ipc_ns->mq_mnt);
  544. if (ret)
  545. goto out;
  546. ret = vfs_create(dir->d_inode, dentry, mode, NULL);
  547. dentry->d_fsdata = NULL;
  548. if (ret)
  549. goto out_drop_write;
  550. result = dentry_open(dentry, ipc_ns->mq_mnt, oflag, cred);
  551. /*
  552. * dentry_open() took a persistent mnt_want_write(),
  553. * so we can now drop this one.
  554. */
  555. mnt_drop_write(ipc_ns->mq_mnt);
  556. return result;
  557. out_drop_write:
  558. mnt_drop_write(ipc_ns->mq_mnt);
  559. out:
  560. dput(dentry);
  561. mntput(ipc_ns->mq_mnt);
  562. return ERR_PTR(ret);
  563. }
  564. /* Opens existing queue */
  565. static struct file *do_open(struct ipc_namespace *ipc_ns,
  566. struct dentry *dentry, int oflag)
  567. {
  568. int ret;
  569. const struct cred *cred = current_cred();
  570. static const int oflag2acc[O_ACCMODE] = { MAY_READ, MAY_WRITE,
  571. MAY_READ | MAY_WRITE };
  572. if ((oflag & O_ACCMODE) == (O_RDWR | O_WRONLY)) {
  573. ret = -EINVAL;
  574. goto err;
  575. }
  576. if (inode_permission(dentry->d_inode, oflag2acc[oflag & O_ACCMODE])) {
  577. ret = -EACCES;
  578. goto err;
  579. }
  580. return dentry_open(dentry, ipc_ns->mq_mnt, oflag, cred);
  581. err:
  582. dput(dentry);
  583. mntput(ipc_ns->mq_mnt);
  584. return ERR_PTR(ret);
  585. }
  586. SYSCALL_DEFINE4(mq_open, const char __user *, u_name, int, oflag, mode_t, mode,
  587. struct mq_attr __user *, u_attr)
  588. {
  589. struct dentry *dentry;
  590. struct file *filp;
  591. char *name;
  592. struct mq_attr attr;
  593. int fd, error;
  594. struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
  595. if (u_attr && copy_from_user(&attr, u_attr, sizeof(struct mq_attr)))
  596. return -EFAULT;
  597. audit_mq_open(oflag, mode, u_attr ? &attr : NULL);
  598. if (IS_ERR(name = getname(u_name)))
  599. return PTR_ERR(name);
  600. fd = get_unused_fd_flags(O_CLOEXEC);
  601. if (fd < 0)
  602. goto out_putname;
  603. mutex_lock(&ipc_ns->mq_mnt->mnt_root->d_inode->i_mutex);
  604. dentry = lookup_one_len(name, ipc_ns->mq_mnt->mnt_root, strlen(name));
  605. if (IS_ERR(dentry)) {
  606. error = PTR_ERR(dentry);
  607. goto out_putfd;
  608. }
  609. mntget(ipc_ns->mq_mnt);
  610. if (oflag & O_CREAT) {
  611. if (dentry->d_inode) { /* entry already exists */
  612. audit_inode(name, dentry);
  613. if (oflag & O_EXCL) {
  614. error = -EEXIST;
  615. goto out;
  616. }
  617. filp = do_open(ipc_ns, dentry, oflag);
  618. } else {
  619. filp = do_create(ipc_ns, ipc_ns->mq_mnt->mnt_root,
  620. dentry, oflag, mode,
  621. u_attr ? &attr : NULL);
  622. }
  623. } else {
  624. if (!dentry->d_inode) {
  625. error = -ENOENT;
  626. goto out;
  627. }
  628. audit_inode(name, dentry);
  629. filp = do_open(ipc_ns, dentry, oflag);
  630. }
  631. if (IS_ERR(filp)) {
  632. error = PTR_ERR(filp);
  633. goto out_putfd;
  634. }
  635. fd_install(fd, filp);
  636. goto out_upsem;
  637. out:
  638. dput(dentry);
  639. mntput(ipc_ns->mq_mnt);
  640. out_putfd:
  641. put_unused_fd(fd);
  642. fd = error;
  643. out_upsem:
  644. mutex_unlock(&ipc_ns->mq_mnt->mnt_root->d_inode->i_mutex);
  645. out_putname:
  646. putname(name);
  647. return fd;
  648. }
  649. SYSCALL_DEFINE1(mq_unlink, const char __user *, u_name)
  650. {
  651. int err;
  652. char *name;
  653. struct dentry *dentry;
  654. struct inode *inode = NULL;
  655. struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
  656. name = getname(u_name);
  657. if (IS_ERR(name))
  658. return PTR_ERR(name);
  659. mutex_lock_nested(&ipc_ns->mq_mnt->mnt_root->d_inode->i_mutex,
  660. I_MUTEX_PARENT);
  661. dentry = lookup_one_len(name, ipc_ns->mq_mnt->mnt_root, strlen(name));
  662. if (IS_ERR(dentry)) {
  663. err = PTR_ERR(dentry);
  664. goto out_unlock;
  665. }
  666. if (!dentry->d_inode) {
  667. err = -ENOENT;
  668. goto out_err;
  669. }
  670. inode = dentry->d_inode;
  671. if (inode)
  672. ihold(inode);
  673. err = mnt_want_write(ipc_ns->mq_mnt);
  674. if (err)
  675. goto out_err;
  676. err = vfs_unlink(dentry->d_parent->d_inode, dentry);
  677. mnt_drop_write(ipc_ns->mq_mnt);
  678. out_err:
  679. dput(dentry);
  680. out_unlock:
  681. mutex_unlock(&ipc_ns->mq_mnt->mnt_root->d_inode->i_mutex);
  682. putname(name);
  683. if (inode)
  684. iput(inode);
  685. return err;
  686. }
  687. /* Pipelined send and receive functions.
  688. *
  689. * If a receiver finds no waiting message, then it registers itself in the
  690. * list of waiting receivers. A sender checks that list before adding the new
  691. * message into the message array. If there is a waiting receiver, then it
  692. * bypasses the message array and directly hands the message over to the
  693. * receiver.
  694. * The receiver accepts the message and returns without grabbing the queue
  695. * spinlock. Therefore an intermediate STATE_PENDING state and memory barriers
  696. * are necessary. The same algorithm is used for sysv semaphores, see
  697. * ipc/sem.c for more details.
  698. *
  699. * The same algorithm is used for senders.
  700. */
  701. /* pipelined_send() - send a message directly to the task waiting in
  702. * sys_mq_timedreceive() (without inserting message into a queue).
  703. */
  704. static inline void pipelined_send(struct mqueue_inode_info *info,
  705. struct msg_msg *message,
  706. struct ext_wait_queue *receiver)
  707. {
  708. receiver->msg = message;
  709. list_del(&receiver->list);
  710. receiver->state = STATE_PENDING;
  711. wake_up_process(receiver->task);
  712. smp_wmb();
  713. receiver->state = STATE_READY;
  714. }
  715. /* pipelined_receive() - if there is task waiting in sys_mq_timedsend()
  716. * gets its message and put to the queue (we have one free place for sure). */
  717. static inline void pipelined_receive(struct mqueue_inode_info *info)
  718. {
  719. struct ext_wait_queue *sender = wq_get_first_waiter(info, SEND);
  720. if (!sender) {
  721. /* for poll */
  722. wake_up_interruptible(&info->wait_q);
  723. return;
  724. }
  725. msg_insert(sender->msg, info);
  726. list_del(&sender->list);
  727. sender->state = STATE_PENDING;
  728. wake_up_process(sender->task);
  729. smp_wmb();
  730. sender->state = STATE_READY;
  731. }
  732. SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr,
  733. size_t, msg_len, unsigned int, msg_prio,
  734. const struct timespec __user *, u_abs_timeout)
  735. {
  736. struct file *filp;
  737. struct inode *inode;
  738. struct ext_wait_queue wait;
  739. struct ext_wait_queue *receiver;
  740. struct msg_msg *msg_ptr;
  741. struct mqueue_inode_info *info;
  742. ktime_t expires, *timeout = NULL;
  743. struct timespec ts;
  744. int ret;
  745. if (u_abs_timeout) {
  746. int res = prepare_timeout(u_abs_timeout, &expires, &ts);
  747. if (res)
  748. return res;
  749. timeout = &expires;
  750. }
  751. if (unlikely(msg_prio >= (unsigned long) MQ_PRIO_MAX))
  752. return -EINVAL;
  753. audit_mq_sendrecv(mqdes, msg_len, msg_prio, timeout ? &ts : NULL);
  754. filp = fget(mqdes);
  755. if (unlikely(!filp)) {
  756. ret = -EBADF;
  757. goto out;
  758. }
  759. inode = filp->f_path.dentry->d_inode;
  760. if (unlikely(filp->f_op != &mqueue_file_operations)) {
  761. ret = -EBADF;
  762. goto out_fput;
  763. }
  764. info = MQUEUE_I(inode);
  765. audit_inode(NULL, filp->f_path.dentry);
  766. if (unlikely(!(filp->f_mode & FMODE_WRITE))) {
  767. ret = -EBADF;
  768. goto out_fput;
  769. }
  770. if (unlikely(msg_len > info->attr.mq_msgsize)) {
  771. ret = -EMSGSIZE;
  772. goto out_fput;
  773. }
  774. /* First try to allocate memory, before doing anything with
  775. * existing queues. */
  776. msg_ptr = load_msg(u_msg_ptr, msg_len);
  777. if (IS_ERR(msg_ptr)) {
  778. ret = PTR_ERR(msg_ptr);
  779. goto out_fput;
  780. }
  781. msg_ptr->m_ts = msg_len;
  782. msg_ptr->m_type = msg_prio;
  783. spin_lock(&info->lock);
  784. if (info->attr.mq_curmsgs == info->attr.mq_maxmsg) {
  785. if (filp->f_flags & O_NONBLOCK) {
  786. spin_unlock(&info->lock);
  787. ret = -EAGAIN;
  788. } else {
  789. wait.task = current;
  790. wait.msg = (void *) msg_ptr;
  791. wait.state = STATE_NONE;
  792. ret = wq_sleep(info, SEND, timeout, &wait);
  793. }
  794. if (ret < 0)
  795. free_msg(msg_ptr);
  796. } else {
  797. receiver = wq_get_first_waiter(info, RECV);
  798. if (receiver) {
  799. pipelined_send(info, msg_ptr, receiver);
  800. } else {
  801. /* adds message to the queue */
  802. msg_insert(msg_ptr, info);
  803. __do_notify(info);
  804. }
  805. inode->i_atime = inode->i_mtime = inode->i_ctime =
  806. CURRENT_TIME;
  807. spin_unlock(&info->lock);
  808. ret = 0;
  809. }
  810. out_fput:
  811. fput(filp);
  812. out:
  813. return ret;
  814. }
  815. SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr,
  816. size_t, msg_len, unsigned int __user *, u_msg_prio,
  817. const struct timespec __user *, u_abs_timeout)
  818. {
  819. ssize_t ret;
  820. struct msg_msg *msg_ptr;
  821. struct file *filp;
  822. struct inode *inode;
  823. struct mqueue_inode_info *info;
  824. struct ext_wait_queue wait;
  825. ktime_t expires, *timeout = NULL;
  826. struct timespec ts;
  827. if (u_abs_timeout) {
  828. int res = prepare_timeout(u_abs_timeout, &expires, &ts);
  829. if (res)
  830. return res;
  831. timeout = &expires;
  832. }
  833. audit_mq_sendrecv(mqdes, msg_len, 0, timeout ? &ts : NULL);
  834. filp = fget(mqdes);
  835. if (unlikely(!filp)) {
  836. ret = -EBADF;
  837. goto out;
  838. }
  839. inode = filp->f_path.dentry->d_inode;
  840. if (unlikely(filp->f_op != &mqueue_file_operations)) {
  841. ret = -EBADF;
  842. goto out_fput;
  843. }
  844. info = MQUEUE_I(inode);
  845. audit_inode(NULL, filp->f_path.dentry);
  846. if (unlikely(!(filp->f_mode & FMODE_READ))) {
  847. ret = -EBADF;
  848. goto out_fput;
  849. }
  850. /* checks if buffer is big enough */
  851. if (unlikely(msg_len < info->attr.mq_msgsize)) {
  852. ret = -EMSGSIZE;
  853. goto out_fput;
  854. }
  855. spin_lock(&info->lock);
  856. if (info->attr.mq_curmsgs == 0) {
  857. if (filp->f_flags & O_NONBLOCK) {
  858. spin_unlock(&info->lock);
  859. ret = -EAGAIN;
  860. } else {
  861. wait.task = current;
  862. wait.state = STATE_NONE;
  863. ret = wq_sleep(info, RECV, timeout, &wait);
  864. msg_ptr = wait.msg;
  865. }
  866. } else {
  867. msg_ptr = msg_get(info);
  868. inode->i_atime = inode->i_mtime = inode->i_ctime =
  869. CURRENT_TIME;
  870. /* There is now free space in queue. */
  871. pipelined_receive(info);
  872. spin_unlock(&info->lock);
  873. ret = 0;
  874. }
  875. if (ret == 0) {
  876. ret = msg_ptr->m_ts;
  877. if ((u_msg_prio && put_user(msg_ptr->m_type, u_msg_prio)) ||
  878. store_msg(u_msg_ptr, msg_ptr, msg_ptr->m_ts)) {
  879. ret = -EFAULT;
  880. }
  881. free_msg(msg_ptr);
  882. }
  883. out_fput:
  884. fput(filp);
  885. out:
  886. return ret;
  887. }
  888. /*
  889. * Notes: the case when user wants us to deregister (with NULL as pointer)
  890. * and he isn't currently owner of notification, will be silently discarded.
  891. * It isn't explicitly defined in the POSIX.
  892. */
  893. SYSCALL_DEFINE2(mq_notify, mqd_t, mqdes,
  894. const struct sigevent __user *, u_notification)
  895. {
  896. int ret;
  897. struct file *filp;
  898. struct sock *sock;
  899. struct inode *inode;
  900. struct sigevent notification;
  901. struct mqueue_inode_info *info;
  902. struct sk_buff *nc;
  903. if (u_notification) {
  904. if (copy_from_user(&notification, u_notification,
  905. sizeof(struct sigevent)))
  906. return -EFAULT;
  907. }
  908. audit_mq_notify(mqdes, u_notification ? &notification : NULL);
  909. nc = NULL;
  910. sock = NULL;
  911. if (u_notification != NULL) {
  912. if (unlikely(notification.sigev_notify != SIGEV_NONE &&
  913. notification.sigev_notify != SIGEV_SIGNAL &&
  914. notification.sigev_notify != SIGEV_THREAD))
  915. return -EINVAL;
  916. if (notification.sigev_notify == SIGEV_SIGNAL &&
  917. !valid_signal(notification.sigev_signo)) {
  918. return -EINVAL;
  919. }
  920. if (notification.sigev_notify == SIGEV_THREAD) {
  921. long timeo;
  922. /* create the notify skb */
  923. nc = alloc_skb(NOTIFY_COOKIE_LEN, GFP_KERNEL);
  924. if (!nc) {
  925. ret = -ENOMEM;
  926. goto out;
  927. }
  928. if (copy_from_user(nc->data,
  929. notification.sigev_value.sival_ptr,
  930. NOTIFY_COOKIE_LEN)) {
  931. ret = -EFAULT;
  932. goto out;
  933. }
  934. /* TODO: add a header? */
  935. skb_put(nc, NOTIFY_COOKIE_LEN);
  936. /* and attach it to the socket */
  937. retry:
  938. filp = fget(notification.sigev_signo);
  939. if (!filp) {
  940. ret = -EBADF;
  941. goto out;
  942. }
  943. sock = netlink_getsockbyfilp(filp);
  944. fput(filp);
  945. if (IS_ERR(sock)) {
  946. ret = PTR_ERR(sock);
  947. sock = NULL;
  948. goto out;
  949. }
  950. timeo = MAX_SCHEDULE_TIMEOUT;
  951. ret = netlink_attachskb(sock, nc, &timeo, NULL);
  952. if (ret == 1)
  953. goto retry;
  954. if (ret) {
  955. sock = NULL;
  956. nc = NULL;
  957. goto out;
  958. }
  959. }
  960. }
  961. filp = fget(mqdes);
  962. if (!filp) {
  963. ret = -EBADF;
  964. goto out;
  965. }
  966. inode = filp->f_path.dentry->d_inode;
  967. if (unlikely(filp->f_op != &mqueue_file_operations)) {
  968. ret = -EBADF;
  969. goto out_fput;
  970. }
  971. info = MQUEUE_I(inode);
  972. ret = 0;
  973. spin_lock(&info->lock);
  974. if (u_notification == NULL) {
  975. if (info->notify_owner == task_tgid(current)) {
  976. remove_notification(info);
  977. inode->i_atime = inode->i_ctime = CURRENT_TIME;
  978. }
  979. } else if (info->notify_owner != NULL) {
  980. ret = -EBUSY;
  981. } else {
  982. switch (notification.sigev_notify) {
  983. case SIGEV_NONE:
  984. info->notify.sigev_notify = SIGEV_NONE;
  985. break;
  986. case SIGEV_THREAD:
  987. info->notify_sock = sock;
  988. info->notify_cookie = nc;
  989. sock = NULL;
  990. nc = NULL;
  991. info->notify.sigev_notify = SIGEV_THREAD;
  992. break;
  993. case SIGEV_SIGNAL:
  994. info->notify.sigev_signo = notification.sigev_signo;
  995. info->notify.sigev_value = notification.sigev_value;
  996. info->notify.sigev_notify = SIGEV_SIGNAL;
  997. break;
  998. }
  999. info->notify_owner = get_pid(task_tgid(current));
  1000. inode->i_atime = inode->i_ctime = CURRENT_TIME;
  1001. }
  1002. spin_unlock(&info->lock);
  1003. out_fput:
  1004. fput(filp);
  1005. out:
  1006. if (sock) {
  1007. netlink_detachskb(sock, nc);
  1008. } else if (nc) {
  1009. dev_kfree_skb(nc);
  1010. }
  1011. return ret;
  1012. }
  1013. SYSCALL_DEFINE3(mq_getsetattr, mqd_t, mqdes,
  1014. const struct mq_attr __user *, u_mqstat,
  1015. struct mq_attr __user *, u_omqstat)
  1016. {
  1017. int ret;
  1018. struct mq_attr mqstat, omqstat;
  1019. struct file *filp;
  1020. struct inode *inode;
  1021. struct mqueue_inode_info *info;
  1022. if (u_mqstat != NULL) {
  1023. if (copy_from_user(&mqstat, u_mqstat, sizeof(struct mq_attr)))
  1024. return -EFAULT;
  1025. if (mqstat.mq_flags & (~O_NONBLOCK))
  1026. return -EINVAL;
  1027. }
  1028. filp = fget(mqdes);
  1029. if (!filp) {
  1030. ret = -EBADF;
  1031. goto out;
  1032. }
  1033. inode = filp->f_path.dentry->d_inode;
  1034. if (unlikely(filp->f_op != &mqueue_file_operations)) {
  1035. ret = -EBADF;
  1036. goto out_fput;
  1037. }
  1038. info = MQUEUE_I(inode);
  1039. spin_lock(&info->lock);
  1040. omqstat = info->attr;
  1041. omqstat.mq_flags = filp->f_flags & O_NONBLOCK;
  1042. if (u_mqstat) {
  1043. audit_mq_getsetattr(mqdes, &mqstat);
  1044. spin_lock(&filp->f_lock);
  1045. if (mqstat.mq_flags & O_NONBLOCK)
  1046. filp->f_flags |= O_NONBLOCK;
  1047. else
  1048. filp->f_flags &= ~O_NONBLOCK;
  1049. spin_unlock(&filp->f_lock);
  1050. inode->i_atime = inode->i_ctime = CURRENT_TIME;
  1051. }
  1052. spin_unlock(&info->lock);
  1053. ret = 0;
  1054. if (u_omqstat != NULL && copy_to_user(u_omqstat, &omqstat,
  1055. sizeof(struct mq_attr)))
  1056. ret = -EFAULT;
  1057. out_fput:
  1058. fput(filp);
  1059. out:
  1060. return ret;
  1061. }
  1062. static const struct inode_operations mqueue_dir_inode_operations = {
  1063. .lookup = simple_lookup,
  1064. .create = mqueue_create,
  1065. .unlink = mqueue_unlink,
  1066. };
  1067. static const struct file_operations mqueue_file_operations = {
  1068. .flush = mqueue_flush_file,
  1069. .poll = mqueue_poll_file,
  1070. .read = mqueue_read_file,
  1071. .llseek = default_llseek,
  1072. };
  1073. static const struct super_operations mqueue_super_ops = {
  1074. .alloc_inode = mqueue_alloc_inode,
  1075. .destroy_inode = mqueue_destroy_inode,
  1076. .evict_inode = mqueue_evict_inode,
  1077. .statfs = simple_statfs,
  1078. };
  1079. static struct file_system_type mqueue_fs_type = {
  1080. .name = "mqueue",
  1081. .mount = mqueue_mount,
  1082. .kill_sb = kill_litter_super,
  1083. };
  1084. int mq_init_ns(struct ipc_namespace *ns)
  1085. {
  1086. ns->mq_queues_count = 0;
  1087. ns->mq_queues_max = DFLT_QUEUESMAX;
  1088. ns->mq_msg_max = DFLT_MSGMAX;
  1089. ns->mq_msgsize_max = DFLT_MSGSIZEMAX;
  1090. ns->mq_mnt = kern_mount_data(&mqueue_fs_type, ns);
  1091. if (IS_ERR(ns->mq_mnt)) {
  1092. int err = PTR_ERR(ns->mq_mnt);
  1093. ns->mq_mnt = NULL;
  1094. return err;
  1095. }
  1096. return 0;
  1097. }
  1098. void mq_clear_sbinfo(struct ipc_namespace *ns)
  1099. {
  1100. ns->mq_mnt->mnt_sb->s_fs_info = NULL;
  1101. }
  1102. void mq_put_mnt(struct ipc_namespace *ns)
  1103. {
  1104. mntput(ns->mq_mnt);
  1105. }
  1106. static int __init init_mqueue_fs(void)
  1107. {
  1108. int error;
  1109. mqueue_inode_cachep = kmem_cache_create("mqueue_inode_cache",
  1110. sizeof(struct mqueue_inode_info), 0,
  1111. SLAB_HWCACHE_ALIGN, init_once);
  1112. if (mqueue_inode_cachep == NULL)
  1113. return -ENOMEM;
  1114. /* ignore failures - they are not fatal */
  1115. mq_sysctl_table = mq_register_sysctl_table();
  1116. error = register_filesystem(&mqueue_fs_type);
  1117. if (error)
  1118. goto out_sysctl;
  1119. spin_lock_init(&mq_lock);
  1120. init_ipc_ns.mq_mnt = kern_mount_data(&mqueue_fs_type, &init_ipc_ns);
  1121. if (IS_ERR(init_ipc_ns.mq_mnt)) {
  1122. error = PTR_ERR(init_ipc_ns.mq_mnt);
  1123. goto out_filesystem;
  1124. }
  1125. return 0;
  1126. out_filesystem:
  1127. unregister_filesystem(&mqueue_fs_type);
  1128. out_sysctl:
  1129. if (mq_sysctl_table)
  1130. unregister_sysctl_table(mq_sysctl_table);
  1131. kmem_cache_destroy(mqueue_inode_cachep);
  1132. return error;
  1133. }
  1134. __initcall(init_mqueue_fs);