mqueue.c 30 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 <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_mode = mode;
  100. inode->i_uid = current_fsuid();
  101. inode->i_gid = current_fsgid();
  102. inode->i_mtime = inode->i_ctime = inode->i_atime =
  103. CURRENT_TIME;
  104. if (S_ISREG(mode)) {
  105. struct mqueue_inode_info *info;
  106. struct task_struct *p = current;
  107. unsigned long mq_bytes, mq_msg_tblsz;
  108. inode->i_fop = &mqueue_file_operations;
  109. inode->i_size = FILENT_SIZE;
  110. /* mqueue specific info */
  111. info = MQUEUE_I(inode);
  112. spin_lock_init(&info->lock);
  113. init_waitqueue_head(&info->wait_q);
  114. INIT_LIST_HEAD(&info->e_wait_q[0].list);
  115. INIT_LIST_HEAD(&info->e_wait_q[1].list);
  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. info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
  128. if (!info->messages)
  129. goto out_inode;
  130. mq_bytes = (mq_msg_tblsz +
  131. (info->attr.mq_maxmsg * info->attr.mq_msgsize));
  132. spin_lock(&mq_lock);
  133. if (u->mq_bytes + mq_bytes < u->mq_bytes ||
  134. u->mq_bytes + mq_bytes >
  135. task_rlimit(p, RLIMIT_MSGQUEUE)) {
  136. spin_unlock(&mq_lock);
  137. /* mqueue_delete_inode() releases info->messages */
  138. goto out_inode;
  139. }
  140. u->mq_bytes += mq_bytes;
  141. spin_unlock(&mq_lock);
  142. /* all is ok */
  143. info->user = get_uid(u);
  144. } else if (S_ISDIR(mode)) {
  145. inc_nlink(inode);
  146. /* Some things misbehave if size == 0 on a directory */
  147. inode->i_size = 2 * DIRENT_SIZE;
  148. inode->i_op = &mqueue_dir_inode_operations;
  149. inode->i_fop = &simple_dir_operations;
  150. }
  151. }
  152. return inode;
  153. out_inode:
  154. make_bad_inode(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 int mqueue_get_sb(struct file_system_type *fs_type,
  184. int flags, const char *dev_name,
  185. void *data, struct vfsmount *mnt)
  186. {
  187. if (!(flags & MS_KERNMOUNT))
  188. data = current->nsproxy->ipc_ns;
  189. return get_sb_ns(fs_type, flags, data, mqueue_fill_super, mnt);
  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_destroy_inode(struct inode *inode)
  205. {
  206. kmem_cache_free(mqueue_inode_cachep, MQUEUE_I(inode));
  207. }
  208. static void mqueue_delete_inode(struct inode *inode)
  209. {
  210. struct mqueue_inode_info *info;
  211. struct user_struct *user;
  212. unsigned long mq_bytes;
  213. int i;
  214. struct ipc_namespace *ipc_ns;
  215. if (S_ISDIR(inode->i_mode)) {
  216. clear_inode(inode);
  217. return;
  218. }
  219. ipc_ns = get_ns_from_inode(inode);
  220. info = MQUEUE_I(inode);
  221. spin_lock(&info->lock);
  222. for (i = 0; i < info->attr.mq_curmsgs; i++)
  223. free_msg(info->messages[i]);
  224. kfree(info->messages);
  225. spin_unlock(&info->lock);
  226. clear_inode(inode);
  227. /* Total amount of bytes accounted for the mqueue */
  228. mq_bytes = info->attr.mq_maxmsg * (sizeof(struct msg_msg *)
  229. + 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. ktime_t *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_hrtimeout_range_clock(timeout,
  378. HRTIMER_MODE_ABS, 0, CLOCK_REALTIME);
  379. while (ewp->state == STATE_PENDING)
  380. cpu_relax();
  381. if (ewp->state == STATE_READY) {
  382. retval = 0;
  383. goto out;
  384. }
  385. spin_lock(&info->lock);
  386. if (ewp->state == STATE_READY) {
  387. retval = 0;
  388. goto out_unlock;
  389. }
  390. if (signal_pending(current)) {
  391. retval = -ERESTARTSYS;
  392. break;
  393. }
  394. if (time == 0) {
  395. retval = -ETIMEDOUT;
  396. break;
  397. }
  398. }
  399. list_del(&ewp->list);
  400. out_unlock:
  401. spin_unlock(&info->lock);
  402. out:
  403. return retval;
  404. }
  405. /*
  406. * Returns waiting task that should be serviced first or NULL if none exists
  407. */
  408. static struct ext_wait_queue *wq_get_first_waiter(
  409. struct mqueue_inode_info *info, int sr)
  410. {
  411. struct list_head *ptr;
  412. ptr = info->e_wait_q[sr].list.prev;
  413. if (ptr == &info->e_wait_q[sr].list)
  414. return NULL;
  415. return list_entry(ptr, struct ext_wait_queue, list);
  416. }
  417. /* Auxiliary functions to manipulate messages' list */
  418. static void msg_insert(struct msg_msg *ptr, struct mqueue_inode_info *info)
  419. {
  420. int k;
  421. k = info->attr.mq_curmsgs - 1;
  422. while (k >= 0 && info->messages[k]->m_type >= ptr->m_type) {
  423. info->messages[k + 1] = info->messages[k];
  424. k--;
  425. }
  426. info->attr.mq_curmsgs++;
  427. info->qsize += ptr->m_ts;
  428. info->messages[k + 1] = ptr;
  429. }
  430. static inline struct msg_msg *msg_get(struct mqueue_inode_info *info)
  431. {
  432. info->qsize -= info->messages[--info->attr.mq_curmsgs]->m_ts;
  433. return info->messages[info->attr.mq_curmsgs];
  434. }
  435. static inline void set_cookie(struct sk_buff *skb, char code)
  436. {
  437. ((char*)skb->data)[NOTIFY_COOKIE_LEN-1] = code;
  438. }
  439. /*
  440. * The next function is only to split too long sys_mq_timedsend
  441. */
  442. static void __do_notify(struct mqueue_inode_info *info)
  443. {
  444. /* notification
  445. * invoked when there is registered process and there isn't process
  446. * waiting synchronously for message AND state of queue changed from
  447. * empty to not empty. Here we are sure that no one is waiting
  448. * synchronously. */
  449. if (info->notify_owner &&
  450. info->attr.mq_curmsgs == 1) {
  451. struct siginfo sig_i;
  452. switch (info->notify.sigev_notify) {
  453. case SIGEV_NONE:
  454. break;
  455. case SIGEV_SIGNAL:
  456. /* sends signal */
  457. sig_i.si_signo = info->notify.sigev_signo;
  458. sig_i.si_errno = 0;
  459. sig_i.si_code = SI_MESGQ;
  460. sig_i.si_value = info->notify.sigev_value;
  461. sig_i.si_pid = task_tgid_nr_ns(current,
  462. ns_of_pid(info->notify_owner));
  463. sig_i.si_uid = current_uid();
  464. kill_pid_info(info->notify.sigev_signo,
  465. &sig_i, info->notify_owner);
  466. break;
  467. case SIGEV_THREAD:
  468. set_cookie(info->notify_cookie, NOTIFY_WOKENUP);
  469. netlink_sendskb(info->notify_sock, info->notify_cookie);
  470. break;
  471. }
  472. /* after notification unregisters process */
  473. put_pid(info->notify_owner);
  474. info->notify_owner = NULL;
  475. }
  476. wake_up(&info->wait_q);
  477. }
  478. static int prepare_timeout(const struct timespec __user *u_abs_timeout,
  479. ktime_t *expires, struct timespec *ts)
  480. {
  481. if (copy_from_user(ts, u_abs_timeout, sizeof(struct timespec)))
  482. return -EFAULT;
  483. if (!timespec_valid(ts))
  484. return -EINVAL;
  485. *expires = timespec_to_ktime(*ts);
  486. return 0;
  487. }
  488. static void remove_notification(struct mqueue_inode_info *info)
  489. {
  490. if (info->notify_owner != NULL &&
  491. info->notify.sigev_notify == SIGEV_THREAD) {
  492. set_cookie(info->notify_cookie, NOTIFY_REMOVED);
  493. netlink_sendskb(info->notify_sock, info->notify_cookie);
  494. }
  495. put_pid(info->notify_owner);
  496. info->notify_owner = NULL;
  497. }
  498. static int mq_attr_ok(struct ipc_namespace *ipc_ns, struct mq_attr *attr)
  499. {
  500. if (attr->mq_maxmsg <= 0 || attr->mq_msgsize <= 0)
  501. return 0;
  502. if (capable(CAP_SYS_RESOURCE)) {
  503. if (attr->mq_maxmsg > HARD_MSGMAX)
  504. return 0;
  505. } else {
  506. if (attr->mq_maxmsg > ipc_ns->mq_msg_max ||
  507. attr->mq_msgsize > ipc_ns->mq_msgsize_max)
  508. return 0;
  509. }
  510. /* check for overflow */
  511. if (attr->mq_msgsize > ULONG_MAX/attr->mq_maxmsg)
  512. return 0;
  513. if ((unsigned long)(attr->mq_maxmsg * (attr->mq_msgsize
  514. + sizeof (struct msg_msg *))) <
  515. (unsigned long)(attr->mq_maxmsg * attr->mq_msgsize))
  516. return 0;
  517. return 1;
  518. }
  519. /*
  520. * Invoked when creating a new queue via sys_mq_open
  521. */
  522. static struct file *do_create(struct ipc_namespace *ipc_ns, struct dentry *dir,
  523. struct dentry *dentry, int oflag, mode_t mode,
  524. struct mq_attr *attr)
  525. {
  526. const struct cred *cred = current_cred();
  527. struct file *result;
  528. int ret;
  529. if (attr) {
  530. if (!mq_attr_ok(ipc_ns, attr)) {
  531. ret = -EINVAL;
  532. goto out;
  533. }
  534. /* store for use during create */
  535. dentry->d_fsdata = attr;
  536. }
  537. mode &= ~current_umask();
  538. ret = mnt_want_write(ipc_ns->mq_mnt);
  539. if (ret)
  540. goto out;
  541. ret = vfs_create(dir->d_inode, dentry, mode, NULL);
  542. dentry->d_fsdata = NULL;
  543. if (ret)
  544. goto out_drop_write;
  545. result = dentry_open(dentry, ipc_ns->mq_mnt, oflag, cred);
  546. /*
  547. * dentry_open() took a persistent mnt_want_write(),
  548. * so we can now drop this one.
  549. */
  550. mnt_drop_write(ipc_ns->mq_mnt);
  551. return result;
  552. out_drop_write:
  553. mnt_drop_write(ipc_ns->mq_mnt);
  554. out:
  555. dput(dentry);
  556. mntput(ipc_ns->mq_mnt);
  557. return ERR_PTR(ret);
  558. }
  559. /* Opens existing queue */
  560. static struct file *do_open(struct ipc_namespace *ipc_ns,
  561. struct dentry *dentry, int oflag)
  562. {
  563. int ret;
  564. const struct cred *cred = current_cred();
  565. static const int oflag2acc[O_ACCMODE] = { MAY_READ, MAY_WRITE,
  566. MAY_READ | MAY_WRITE };
  567. if ((oflag & O_ACCMODE) == (O_RDWR | O_WRONLY)) {
  568. ret = -EINVAL;
  569. goto err;
  570. }
  571. if (inode_permission(dentry->d_inode, oflag2acc[oflag & O_ACCMODE])) {
  572. ret = -EACCES;
  573. goto err;
  574. }
  575. return dentry_open(dentry, ipc_ns->mq_mnt, oflag, cred);
  576. err:
  577. dput(dentry);
  578. mntput(ipc_ns->mq_mnt);
  579. return ERR_PTR(ret);
  580. }
  581. SYSCALL_DEFINE4(mq_open, const char __user *, u_name, int, oflag, mode_t, mode,
  582. struct mq_attr __user *, u_attr)
  583. {
  584. struct dentry *dentry;
  585. struct file *filp;
  586. char *name;
  587. struct mq_attr attr;
  588. int fd, error;
  589. struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
  590. if (u_attr && copy_from_user(&attr, u_attr, sizeof(struct mq_attr)))
  591. return -EFAULT;
  592. audit_mq_open(oflag, mode, u_attr ? &attr : NULL);
  593. if (IS_ERR(name = getname(u_name)))
  594. return PTR_ERR(name);
  595. fd = get_unused_fd_flags(O_CLOEXEC);
  596. if (fd < 0)
  597. goto out_putname;
  598. mutex_lock(&ipc_ns->mq_mnt->mnt_root->d_inode->i_mutex);
  599. dentry = lookup_one_len(name, ipc_ns->mq_mnt->mnt_root, strlen(name));
  600. if (IS_ERR(dentry)) {
  601. error = PTR_ERR(dentry);
  602. goto out_putfd;
  603. }
  604. mntget(ipc_ns->mq_mnt);
  605. if (oflag & O_CREAT) {
  606. if (dentry->d_inode) { /* entry already exists */
  607. audit_inode(name, dentry);
  608. if (oflag & O_EXCL) {
  609. error = -EEXIST;
  610. goto out;
  611. }
  612. filp = do_open(ipc_ns, dentry, oflag);
  613. } else {
  614. filp = do_create(ipc_ns, ipc_ns->mq_mnt->mnt_root,
  615. dentry, oflag, mode,
  616. u_attr ? &attr : NULL);
  617. }
  618. } else {
  619. if (!dentry->d_inode) {
  620. error = -ENOENT;
  621. goto out;
  622. }
  623. audit_inode(name, dentry);
  624. filp = do_open(ipc_ns, dentry, oflag);
  625. }
  626. if (IS_ERR(filp)) {
  627. error = PTR_ERR(filp);
  628. goto out_putfd;
  629. }
  630. fd_install(fd, filp);
  631. goto out_upsem;
  632. out:
  633. dput(dentry);
  634. mntput(ipc_ns->mq_mnt);
  635. out_putfd:
  636. put_unused_fd(fd);
  637. fd = error;
  638. out_upsem:
  639. mutex_unlock(&ipc_ns->mq_mnt->mnt_root->d_inode->i_mutex);
  640. out_putname:
  641. putname(name);
  642. return fd;
  643. }
  644. SYSCALL_DEFINE1(mq_unlink, const char __user *, u_name)
  645. {
  646. int err;
  647. char *name;
  648. struct dentry *dentry;
  649. struct inode *inode = NULL;
  650. struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
  651. name = getname(u_name);
  652. if (IS_ERR(name))
  653. return PTR_ERR(name);
  654. mutex_lock_nested(&ipc_ns->mq_mnt->mnt_root->d_inode->i_mutex,
  655. I_MUTEX_PARENT);
  656. dentry = lookup_one_len(name, ipc_ns->mq_mnt->mnt_root, strlen(name));
  657. if (IS_ERR(dentry)) {
  658. err = PTR_ERR(dentry);
  659. goto out_unlock;
  660. }
  661. if (!dentry->d_inode) {
  662. err = -ENOENT;
  663. goto out_err;
  664. }
  665. inode = dentry->d_inode;
  666. if (inode)
  667. atomic_inc(&inode->i_count);
  668. err = mnt_want_write(ipc_ns->mq_mnt);
  669. if (err)
  670. goto out_err;
  671. err = vfs_unlink(dentry->d_parent->d_inode, dentry);
  672. mnt_drop_write(ipc_ns->mq_mnt);
  673. out_err:
  674. dput(dentry);
  675. out_unlock:
  676. mutex_unlock(&ipc_ns->mq_mnt->mnt_root->d_inode->i_mutex);
  677. putname(name);
  678. if (inode)
  679. iput(inode);
  680. return err;
  681. }
  682. /* Pipelined send and receive functions.
  683. *
  684. * If a receiver finds no waiting message, then it registers itself in the
  685. * list of waiting receivers. A sender checks that list before adding the new
  686. * message into the message array. If there is a waiting receiver, then it
  687. * bypasses the message array and directly hands the message over to the
  688. * receiver.
  689. * The receiver accepts the message and returns without grabbing the queue
  690. * spinlock. Therefore an intermediate STATE_PENDING state and memory barriers
  691. * are necessary. The same algorithm is used for sysv semaphores, see
  692. * ipc/sem.c for more details.
  693. *
  694. * The same algorithm is used for senders.
  695. */
  696. /* pipelined_send() - send a message directly to the task waiting in
  697. * sys_mq_timedreceive() (without inserting message into a queue).
  698. */
  699. static inline void pipelined_send(struct mqueue_inode_info *info,
  700. struct msg_msg *message,
  701. struct ext_wait_queue *receiver)
  702. {
  703. receiver->msg = message;
  704. list_del(&receiver->list);
  705. receiver->state = STATE_PENDING;
  706. wake_up_process(receiver->task);
  707. smp_wmb();
  708. receiver->state = STATE_READY;
  709. }
  710. /* pipelined_receive() - if there is task waiting in sys_mq_timedsend()
  711. * gets its message and put to the queue (we have one free place for sure). */
  712. static inline void pipelined_receive(struct mqueue_inode_info *info)
  713. {
  714. struct ext_wait_queue *sender = wq_get_first_waiter(info, SEND);
  715. if (!sender) {
  716. /* for poll */
  717. wake_up_interruptible(&info->wait_q);
  718. return;
  719. }
  720. msg_insert(sender->msg, info);
  721. list_del(&sender->list);
  722. sender->state = STATE_PENDING;
  723. wake_up_process(sender->task);
  724. smp_wmb();
  725. sender->state = STATE_READY;
  726. }
  727. SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr,
  728. size_t, msg_len, unsigned int, msg_prio,
  729. const struct timespec __user *, u_abs_timeout)
  730. {
  731. struct file *filp;
  732. struct inode *inode;
  733. struct ext_wait_queue wait;
  734. struct ext_wait_queue *receiver;
  735. struct msg_msg *msg_ptr;
  736. struct mqueue_inode_info *info;
  737. ktime_t expires, *timeout = NULL;
  738. struct timespec ts;
  739. int ret;
  740. if (u_abs_timeout) {
  741. int res = prepare_timeout(u_abs_timeout, &expires, &ts);
  742. if (res)
  743. return res;
  744. timeout = &expires;
  745. }
  746. if (unlikely(msg_prio >= (unsigned long) MQ_PRIO_MAX))
  747. return -EINVAL;
  748. audit_mq_sendrecv(mqdes, msg_len, msg_prio, timeout ? &ts : NULL);
  749. filp = fget(mqdes);
  750. if (unlikely(!filp)) {
  751. ret = -EBADF;
  752. goto out;
  753. }
  754. inode = filp->f_path.dentry->d_inode;
  755. if (unlikely(filp->f_op != &mqueue_file_operations)) {
  756. ret = -EBADF;
  757. goto out_fput;
  758. }
  759. info = MQUEUE_I(inode);
  760. audit_inode(NULL, filp->f_path.dentry);
  761. if (unlikely(!(filp->f_mode & FMODE_WRITE))) {
  762. ret = -EBADF;
  763. goto out_fput;
  764. }
  765. if (unlikely(msg_len > info->attr.mq_msgsize)) {
  766. ret = -EMSGSIZE;
  767. goto out_fput;
  768. }
  769. /* First try to allocate memory, before doing anything with
  770. * existing queues. */
  771. msg_ptr = load_msg(u_msg_ptr, msg_len);
  772. if (IS_ERR(msg_ptr)) {
  773. ret = PTR_ERR(msg_ptr);
  774. goto out_fput;
  775. }
  776. msg_ptr->m_ts = msg_len;
  777. msg_ptr->m_type = msg_prio;
  778. spin_lock(&info->lock);
  779. if (info->attr.mq_curmsgs == info->attr.mq_maxmsg) {
  780. if (filp->f_flags & O_NONBLOCK) {
  781. spin_unlock(&info->lock);
  782. ret = -EAGAIN;
  783. } else {
  784. wait.task = current;
  785. wait.msg = (void *) msg_ptr;
  786. wait.state = STATE_NONE;
  787. ret = wq_sleep(info, SEND, timeout, &wait);
  788. }
  789. if (ret < 0)
  790. free_msg(msg_ptr);
  791. } else {
  792. receiver = wq_get_first_waiter(info, RECV);
  793. if (receiver) {
  794. pipelined_send(info, msg_ptr, receiver);
  795. } else {
  796. /* adds message to the queue */
  797. msg_insert(msg_ptr, info);
  798. __do_notify(info);
  799. }
  800. inode->i_atime = inode->i_mtime = inode->i_ctime =
  801. CURRENT_TIME;
  802. spin_unlock(&info->lock);
  803. ret = 0;
  804. }
  805. out_fput:
  806. fput(filp);
  807. out:
  808. return ret;
  809. }
  810. SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr,
  811. size_t, msg_len, unsigned int __user *, u_msg_prio,
  812. const struct timespec __user *, u_abs_timeout)
  813. {
  814. ssize_t ret;
  815. struct msg_msg *msg_ptr;
  816. struct file *filp;
  817. struct inode *inode;
  818. struct mqueue_inode_info *info;
  819. struct ext_wait_queue wait;
  820. ktime_t expires, *timeout = NULL;
  821. struct timespec ts;
  822. if (u_abs_timeout) {
  823. int res = prepare_timeout(u_abs_timeout, &expires, &ts);
  824. if (res)
  825. return res;
  826. timeout = &expires;
  827. }
  828. audit_mq_sendrecv(mqdes, msg_len, 0, timeout ? &ts : NULL);
  829. filp = fget(mqdes);
  830. if (unlikely(!filp)) {
  831. ret = -EBADF;
  832. goto out;
  833. }
  834. inode = filp->f_path.dentry->d_inode;
  835. if (unlikely(filp->f_op != &mqueue_file_operations)) {
  836. ret = -EBADF;
  837. goto out_fput;
  838. }
  839. info = MQUEUE_I(inode);
  840. audit_inode(NULL, filp->f_path.dentry);
  841. if (unlikely(!(filp->f_mode & FMODE_READ))) {
  842. ret = -EBADF;
  843. goto out_fput;
  844. }
  845. /* checks if buffer is big enough */
  846. if (unlikely(msg_len < info->attr.mq_msgsize)) {
  847. ret = -EMSGSIZE;
  848. goto out_fput;
  849. }
  850. spin_lock(&info->lock);
  851. if (info->attr.mq_curmsgs == 0) {
  852. if (filp->f_flags & O_NONBLOCK) {
  853. spin_unlock(&info->lock);
  854. ret = -EAGAIN;
  855. } else {
  856. wait.task = current;
  857. wait.state = STATE_NONE;
  858. ret = wq_sleep(info, RECV, timeout, &wait);
  859. msg_ptr = wait.msg;
  860. }
  861. } else {
  862. msg_ptr = msg_get(info);
  863. inode->i_atime = inode->i_mtime = inode->i_ctime =
  864. CURRENT_TIME;
  865. /* There is now free space in queue. */
  866. pipelined_receive(info);
  867. spin_unlock(&info->lock);
  868. ret = 0;
  869. }
  870. if (ret == 0) {
  871. ret = msg_ptr->m_ts;
  872. if ((u_msg_prio && put_user(msg_ptr->m_type, u_msg_prio)) ||
  873. store_msg(u_msg_ptr, msg_ptr, msg_ptr->m_ts)) {
  874. ret = -EFAULT;
  875. }
  876. free_msg(msg_ptr);
  877. }
  878. out_fput:
  879. fput(filp);
  880. out:
  881. return ret;
  882. }
  883. /*
  884. * Notes: the case when user wants us to deregister (with NULL as pointer)
  885. * and he isn't currently owner of notification, will be silently discarded.
  886. * It isn't explicitly defined in the POSIX.
  887. */
  888. SYSCALL_DEFINE2(mq_notify, mqd_t, mqdes,
  889. const struct sigevent __user *, u_notification)
  890. {
  891. int ret;
  892. struct file *filp;
  893. struct sock *sock;
  894. struct inode *inode;
  895. struct sigevent notification;
  896. struct mqueue_inode_info *info;
  897. struct sk_buff *nc;
  898. if (u_notification) {
  899. if (copy_from_user(&notification, u_notification,
  900. sizeof(struct sigevent)))
  901. return -EFAULT;
  902. }
  903. audit_mq_notify(mqdes, u_notification ? &notification : NULL);
  904. nc = NULL;
  905. sock = NULL;
  906. if (u_notification != NULL) {
  907. if (unlikely(notification.sigev_notify != SIGEV_NONE &&
  908. notification.sigev_notify != SIGEV_SIGNAL &&
  909. notification.sigev_notify != SIGEV_THREAD))
  910. return -EINVAL;
  911. if (notification.sigev_notify == SIGEV_SIGNAL &&
  912. !valid_signal(notification.sigev_signo)) {
  913. return -EINVAL;
  914. }
  915. if (notification.sigev_notify == SIGEV_THREAD) {
  916. long timeo;
  917. /* create the notify skb */
  918. nc = alloc_skb(NOTIFY_COOKIE_LEN, GFP_KERNEL);
  919. if (!nc) {
  920. ret = -ENOMEM;
  921. goto out;
  922. }
  923. if (copy_from_user(nc->data,
  924. notification.sigev_value.sival_ptr,
  925. NOTIFY_COOKIE_LEN)) {
  926. ret = -EFAULT;
  927. goto out;
  928. }
  929. /* TODO: add a header? */
  930. skb_put(nc, NOTIFY_COOKIE_LEN);
  931. /* and attach it to the socket */
  932. retry:
  933. filp = fget(notification.sigev_signo);
  934. if (!filp) {
  935. ret = -EBADF;
  936. goto out;
  937. }
  938. sock = netlink_getsockbyfilp(filp);
  939. fput(filp);
  940. if (IS_ERR(sock)) {
  941. ret = PTR_ERR(sock);
  942. sock = NULL;
  943. goto out;
  944. }
  945. timeo = MAX_SCHEDULE_TIMEOUT;
  946. ret = netlink_attachskb(sock, nc, &timeo, NULL);
  947. if (ret == 1)
  948. goto retry;
  949. if (ret) {
  950. sock = NULL;
  951. nc = NULL;
  952. goto out;
  953. }
  954. }
  955. }
  956. filp = fget(mqdes);
  957. if (!filp) {
  958. ret = -EBADF;
  959. goto out;
  960. }
  961. inode = filp->f_path.dentry->d_inode;
  962. if (unlikely(filp->f_op != &mqueue_file_operations)) {
  963. ret = -EBADF;
  964. goto out_fput;
  965. }
  966. info = MQUEUE_I(inode);
  967. ret = 0;
  968. spin_lock(&info->lock);
  969. if (u_notification == NULL) {
  970. if (info->notify_owner == task_tgid(current)) {
  971. remove_notification(info);
  972. inode->i_atime = inode->i_ctime = CURRENT_TIME;
  973. }
  974. } else if (info->notify_owner != NULL) {
  975. ret = -EBUSY;
  976. } else {
  977. switch (notification.sigev_notify) {
  978. case SIGEV_NONE:
  979. info->notify.sigev_notify = SIGEV_NONE;
  980. break;
  981. case SIGEV_THREAD:
  982. info->notify_sock = sock;
  983. info->notify_cookie = nc;
  984. sock = NULL;
  985. nc = NULL;
  986. info->notify.sigev_notify = SIGEV_THREAD;
  987. break;
  988. case SIGEV_SIGNAL:
  989. info->notify.sigev_signo = notification.sigev_signo;
  990. info->notify.sigev_value = notification.sigev_value;
  991. info->notify.sigev_notify = SIGEV_SIGNAL;
  992. break;
  993. }
  994. info->notify_owner = get_pid(task_tgid(current));
  995. inode->i_atime = inode->i_ctime = CURRENT_TIME;
  996. }
  997. spin_unlock(&info->lock);
  998. out_fput:
  999. fput(filp);
  1000. out:
  1001. if (sock) {
  1002. netlink_detachskb(sock, nc);
  1003. } else if (nc) {
  1004. dev_kfree_skb(nc);
  1005. }
  1006. return ret;
  1007. }
  1008. SYSCALL_DEFINE3(mq_getsetattr, mqd_t, mqdes,
  1009. const struct mq_attr __user *, u_mqstat,
  1010. struct mq_attr __user *, u_omqstat)
  1011. {
  1012. int ret;
  1013. struct mq_attr mqstat, omqstat;
  1014. struct file *filp;
  1015. struct inode *inode;
  1016. struct mqueue_inode_info *info;
  1017. if (u_mqstat != NULL) {
  1018. if (copy_from_user(&mqstat, u_mqstat, sizeof(struct mq_attr)))
  1019. return -EFAULT;
  1020. if (mqstat.mq_flags & (~O_NONBLOCK))
  1021. return -EINVAL;
  1022. }
  1023. filp = fget(mqdes);
  1024. if (!filp) {
  1025. ret = -EBADF;
  1026. goto out;
  1027. }
  1028. inode = filp->f_path.dentry->d_inode;
  1029. if (unlikely(filp->f_op != &mqueue_file_operations)) {
  1030. ret = -EBADF;
  1031. goto out_fput;
  1032. }
  1033. info = MQUEUE_I(inode);
  1034. spin_lock(&info->lock);
  1035. omqstat = info->attr;
  1036. omqstat.mq_flags = filp->f_flags & O_NONBLOCK;
  1037. if (u_mqstat) {
  1038. audit_mq_getsetattr(mqdes, &mqstat);
  1039. spin_lock(&filp->f_lock);
  1040. if (mqstat.mq_flags & O_NONBLOCK)
  1041. filp->f_flags |= O_NONBLOCK;
  1042. else
  1043. filp->f_flags &= ~O_NONBLOCK;
  1044. spin_unlock(&filp->f_lock);
  1045. inode->i_atime = inode->i_ctime = CURRENT_TIME;
  1046. }
  1047. spin_unlock(&info->lock);
  1048. ret = 0;
  1049. if (u_omqstat != NULL && copy_to_user(u_omqstat, &omqstat,
  1050. sizeof(struct mq_attr)))
  1051. ret = -EFAULT;
  1052. out_fput:
  1053. fput(filp);
  1054. out:
  1055. return ret;
  1056. }
  1057. static const struct inode_operations mqueue_dir_inode_operations = {
  1058. .lookup = simple_lookup,
  1059. .create = mqueue_create,
  1060. .unlink = mqueue_unlink,
  1061. };
  1062. static const struct file_operations mqueue_file_operations = {
  1063. .flush = mqueue_flush_file,
  1064. .poll = mqueue_poll_file,
  1065. .read = mqueue_read_file,
  1066. };
  1067. static const struct super_operations mqueue_super_ops = {
  1068. .alloc_inode = mqueue_alloc_inode,
  1069. .destroy_inode = mqueue_destroy_inode,
  1070. .statfs = simple_statfs,
  1071. .delete_inode = mqueue_delete_inode,
  1072. .drop_inode = generic_delete_inode,
  1073. };
  1074. static struct file_system_type mqueue_fs_type = {
  1075. .name = "mqueue",
  1076. .get_sb = mqueue_get_sb,
  1077. .kill_sb = kill_litter_super,
  1078. };
  1079. int mq_init_ns(struct ipc_namespace *ns)
  1080. {
  1081. ns->mq_queues_count = 0;
  1082. ns->mq_queues_max = DFLT_QUEUESMAX;
  1083. ns->mq_msg_max = DFLT_MSGMAX;
  1084. ns->mq_msgsize_max = DFLT_MSGSIZEMAX;
  1085. ns->mq_mnt = kern_mount_data(&mqueue_fs_type, ns);
  1086. if (IS_ERR(ns->mq_mnt)) {
  1087. int err = PTR_ERR(ns->mq_mnt);
  1088. ns->mq_mnt = NULL;
  1089. return err;
  1090. }
  1091. return 0;
  1092. }
  1093. void mq_clear_sbinfo(struct ipc_namespace *ns)
  1094. {
  1095. ns->mq_mnt->mnt_sb->s_fs_info = NULL;
  1096. }
  1097. void mq_put_mnt(struct ipc_namespace *ns)
  1098. {
  1099. mntput(ns->mq_mnt);
  1100. }
  1101. static int __init init_mqueue_fs(void)
  1102. {
  1103. int error;
  1104. mqueue_inode_cachep = kmem_cache_create("mqueue_inode_cache",
  1105. sizeof(struct mqueue_inode_info), 0,
  1106. SLAB_HWCACHE_ALIGN, init_once);
  1107. if (mqueue_inode_cachep == NULL)
  1108. return -ENOMEM;
  1109. /* ignore failures - they are not fatal */
  1110. mq_sysctl_table = mq_register_sysctl_table();
  1111. error = register_filesystem(&mqueue_fs_type);
  1112. if (error)
  1113. goto out_sysctl;
  1114. spin_lock_init(&mq_lock);
  1115. init_ipc_ns.mq_mnt = kern_mount_data(&mqueue_fs_type, &init_ipc_ns);
  1116. if (IS_ERR(init_ipc_ns.mq_mnt)) {
  1117. error = PTR_ERR(init_ipc_ns.mq_mnt);
  1118. goto out_filesystem;
  1119. }
  1120. return 0;
  1121. out_filesystem:
  1122. unregister_filesystem(&mqueue_fs_type);
  1123. out_sysctl:
  1124. if (mq_sysctl_table)
  1125. unregister_sysctl_table(mq_sysctl_table);
  1126. kmem_cache_destroy(mqueue_inode_cachep);
  1127. return error;
  1128. }
  1129. __initcall(init_mqueue_fs);