mqueue.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311
  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);