mqueue.c 31 KB

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