mqueue.c 31 KB

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