mqueue.c 31 KB

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