inode.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. /*
  2. * SPU file system
  3. *
  4. * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
  5. *
  6. * Author: Arnd Bergmann <arndb@de.ibm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2, or (at your option)
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/file.h>
  23. #include <linux/fs.h>
  24. #include <linux/backing-dev.h>
  25. #include <linux/init.h>
  26. #include <linux/ioctl.h>
  27. #include <linux/module.h>
  28. #include <linux/mount.h>
  29. #include <linux/namei.h>
  30. #include <linux/pagemap.h>
  31. #include <linux/poll.h>
  32. #include <linux/slab.h>
  33. #include <linux/parser.h>
  34. #include <asm/prom.h>
  35. #include <asm/semaphore.h>
  36. #include <asm/spu.h>
  37. #include <asm/spu_priv1.h>
  38. #include <asm/uaccess.h>
  39. #include "spufs.h"
  40. static struct kmem_cache *spufs_inode_cache;
  41. char *isolated_loader;
  42. static struct inode *
  43. spufs_alloc_inode(struct super_block *sb)
  44. {
  45. struct spufs_inode_info *ei;
  46. ei = kmem_cache_alloc(spufs_inode_cache, GFP_KERNEL);
  47. if (!ei)
  48. return NULL;
  49. ei->i_gang = NULL;
  50. ei->i_ctx = NULL;
  51. ei->i_openers = 0;
  52. return &ei->vfs_inode;
  53. }
  54. static void
  55. spufs_destroy_inode(struct inode *inode)
  56. {
  57. kmem_cache_free(spufs_inode_cache, SPUFS_I(inode));
  58. }
  59. static void
  60. spufs_init_once(void *p, struct kmem_cache * cachep, unsigned long flags)
  61. {
  62. struct spufs_inode_info *ei = p;
  63. inode_init_once(&ei->vfs_inode);
  64. }
  65. static struct inode *
  66. spufs_new_inode(struct super_block *sb, int mode)
  67. {
  68. struct inode *inode;
  69. inode = new_inode(sb);
  70. if (!inode)
  71. goto out;
  72. inode->i_mode = mode;
  73. inode->i_uid = current->fsuid;
  74. inode->i_gid = current->fsgid;
  75. inode->i_blocks = 0;
  76. inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  77. out:
  78. return inode;
  79. }
  80. static int
  81. spufs_setattr(struct dentry *dentry, struct iattr *attr)
  82. {
  83. struct inode *inode = dentry->d_inode;
  84. if ((attr->ia_valid & ATTR_SIZE) &&
  85. (attr->ia_size != inode->i_size))
  86. return -EINVAL;
  87. return inode_setattr(inode, attr);
  88. }
  89. static int
  90. spufs_new_file(struct super_block *sb, struct dentry *dentry,
  91. const struct file_operations *fops, int mode,
  92. struct spu_context *ctx)
  93. {
  94. static struct inode_operations spufs_file_iops = {
  95. .setattr = spufs_setattr,
  96. };
  97. struct inode *inode;
  98. int ret;
  99. ret = -ENOSPC;
  100. inode = spufs_new_inode(sb, S_IFREG | mode);
  101. if (!inode)
  102. goto out;
  103. ret = 0;
  104. inode->i_op = &spufs_file_iops;
  105. inode->i_fop = fops;
  106. inode->i_private = SPUFS_I(inode)->i_ctx = get_spu_context(ctx);
  107. d_add(dentry, inode);
  108. out:
  109. return ret;
  110. }
  111. static void
  112. spufs_delete_inode(struct inode *inode)
  113. {
  114. struct spufs_inode_info *ei = SPUFS_I(inode);
  115. if (ei->i_ctx)
  116. put_spu_context(ei->i_ctx);
  117. if (ei->i_gang)
  118. put_spu_gang(ei->i_gang);
  119. clear_inode(inode);
  120. }
  121. static void spufs_prune_dir(struct dentry *dir)
  122. {
  123. struct dentry *dentry, *tmp;
  124. mutex_lock(&dir->d_inode->i_mutex);
  125. list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
  126. spin_lock(&dcache_lock);
  127. spin_lock(&dentry->d_lock);
  128. if (!(d_unhashed(dentry)) && dentry->d_inode) {
  129. dget_locked(dentry);
  130. __d_drop(dentry);
  131. spin_unlock(&dentry->d_lock);
  132. simple_unlink(dir->d_inode, dentry);
  133. spin_unlock(&dcache_lock);
  134. dput(dentry);
  135. } else {
  136. spin_unlock(&dentry->d_lock);
  137. spin_unlock(&dcache_lock);
  138. }
  139. }
  140. shrink_dcache_parent(dir);
  141. mutex_unlock(&dir->d_inode->i_mutex);
  142. }
  143. /* Caller must hold parent->i_mutex */
  144. static int spufs_rmdir(struct inode *parent, struct dentry *dir)
  145. {
  146. /* remove all entries */
  147. spufs_prune_dir(dir);
  148. return simple_rmdir(parent, dir);
  149. }
  150. static int spufs_fill_dir(struct dentry *dir, struct tree_descr *files,
  151. int mode, struct spu_context *ctx)
  152. {
  153. struct dentry *dentry, *tmp;
  154. int ret;
  155. while (files->name && files->name[0]) {
  156. ret = -ENOMEM;
  157. dentry = d_alloc_name(dir, files->name);
  158. if (!dentry)
  159. goto out;
  160. ret = spufs_new_file(dir->d_sb, dentry, files->ops,
  161. files->mode & mode, ctx);
  162. if (ret)
  163. goto out;
  164. files++;
  165. }
  166. return 0;
  167. out:
  168. /*
  169. * remove all children from dir. dir->inode is not set so don't
  170. * just simply use spufs_prune_dir() and panic afterwards :)
  171. * dput() looks like it will do the right thing:
  172. * - dec parent's ref counter
  173. * - remove child from parent's child list
  174. * - free child's inode if possible
  175. * - free child
  176. */
  177. list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
  178. dput(dentry);
  179. }
  180. shrink_dcache_parent(dir);
  181. return ret;
  182. }
  183. static int spufs_dir_close(struct inode *inode, struct file *file)
  184. {
  185. struct spu_context *ctx;
  186. struct inode *parent;
  187. struct dentry *dir;
  188. int ret;
  189. dir = file->f_path.dentry;
  190. parent = dir->d_parent->d_inode;
  191. ctx = SPUFS_I(dir->d_inode)->i_ctx;
  192. mutex_lock(&parent->i_mutex);
  193. ret = spufs_rmdir(parent, dir);
  194. mutex_unlock(&parent->i_mutex);
  195. WARN_ON(ret);
  196. /* We have to give up the mm_struct */
  197. spu_forget(ctx);
  198. return dcache_dir_close(inode, file);
  199. }
  200. const struct file_operations spufs_context_fops = {
  201. .open = dcache_dir_open,
  202. .release = spufs_dir_close,
  203. .llseek = dcache_dir_lseek,
  204. .read = generic_read_dir,
  205. .readdir = dcache_readdir,
  206. .fsync = simple_sync_file,
  207. };
  208. EXPORT_SYMBOL_GPL(spufs_context_fops);
  209. static int
  210. spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
  211. int mode)
  212. {
  213. int ret;
  214. struct inode *inode;
  215. struct spu_context *ctx;
  216. ret = -ENOSPC;
  217. inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
  218. if (!inode)
  219. goto out;
  220. if (dir->i_mode & S_ISGID) {
  221. inode->i_gid = dir->i_gid;
  222. inode->i_mode &= S_ISGID;
  223. }
  224. ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */
  225. SPUFS_I(inode)->i_ctx = ctx;
  226. if (!ctx)
  227. goto out_iput;
  228. ctx->flags = flags;
  229. inode->i_op = &simple_dir_inode_operations;
  230. inode->i_fop = &simple_dir_operations;
  231. if (flags & SPU_CREATE_NOSCHED)
  232. ret = spufs_fill_dir(dentry, spufs_dir_nosched_contents,
  233. mode, ctx);
  234. else
  235. ret = spufs_fill_dir(dentry, spufs_dir_contents, mode, ctx);
  236. if (ret)
  237. goto out_free_ctx;
  238. d_instantiate(dentry, inode);
  239. dget(dentry);
  240. dir->i_nlink++;
  241. dentry->d_inode->i_nlink++;
  242. goto out;
  243. out_free_ctx:
  244. spu_forget(ctx);
  245. put_spu_context(ctx);
  246. out_iput:
  247. iput(inode);
  248. out:
  249. return ret;
  250. }
  251. static int spufs_context_open(struct dentry *dentry, struct vfsmount *mnt)
  252. {
  253. int ret;
  254. struct file *filp;
  255. ret = get_unused_fd();
  256. if (ret < 0) {
  257. dput(dentry);
  258. mntput(mnt);
  259. goto out;
  260. }
  261. filp = dentry_open(dentry, mnt, O_RDONLY);
  262. if (IS_ERR(filp)) {
  263. put_unused_fd(ret);
  264. ret = PTR_ERR(filp);
  265. goto out;
  266. }
  267. filp->f_op = &spufs_context_fops;
  268. fd_install(ret, filp);
  269. out:
  270. return ret;
  271. }
  272. static struct spu_context *
  273. spufs_assert_affinity(unsigned int flags, struct spu_gang *gang,
  274. struct file *filp)
  275. {
  276. struct spu_context *tmp, *neighbor;
  277. int count, node;
  278. int aff_supp;
  279. aff_supp = !list_empty(&(list_entry(cbe_spu_info[0].spus.next,
  280. struct spu, cbe_list))->aff_list);
  281. if (!aff_supp)
  282. return ERR_PTR(-EINVAL);
  283. if (flags & SPU_CREATE_GANG)
  284. return ERR_PTR(-EINVAL);
  285. if (flags & SPU_CREATE_AFFINITY_MEM &&
  286. gang->aff_ref_ctx &&
  287. gang->aff_ref_ctx->flags & SPU_CREATE_AFFINITY_MEM)
  288. return ERR_PTR(-EEXIST);
  289. if (gang->aff_flags & AFF_MERGED)
  290. return ERR_PTR(-EBUSY);
  291. neighbor = NULL;
  292. if (flags & SPU_CREATE_AFFINITY_SPU) {
  293. if (!filp || filp->f_op != &spufs_context_fops)
  294. return ERR_PTR(-EINVAL);
  295. neighbor = get_spu_context(
  296. SPUFS_I(filp->f_dentry->d_inode)->i_ctx);
  297. if (!list_empty(&neighbor->aff_list) && !(neighbor->aff_head) &&
  298. !list_is_last(&neighbor->aff_list, &gang->aff_list_head) &&
  299. !list_entry(neighbor->aff_list.next, struct spu_context,
  300. aff_list)->aff_head)
  301. return ERR_PTR(-EEXIST);
  302. if (gang != neighbor->gang)
  303. return ERR_PTR(-EINVAL);
  304. count = 1;
  305. list_for_each_entry(tmp, &gang->aff_list_head, aff_list)
  306. count++;
  307. if (list_empty(&neighbor->aff_list))
  308. count++;
  309. for (node = 0; node < MAX_NUMNODES; node++) {
  310. if ((cbe_spu_info[node].n_spus - atomic_read(
  311. &cbe_spu_info[node].reserved_spus)) >= count)
  312. break;
  313. }
  314. if (node == MAX_NUMNODES)
  315. return ERR_PTR(-EEXIST);
  316. }
  317. return neighbor;
  318. }
  319. static void
  320. spufs_set_affinity(unsigned int flags, struct spu_context *ctx,
  321. struct spu_context *neighbor)
  322. {
  323. if (flags & SPU_CREATE_AFFINITY_MEM)
  324. ctx->gang->aff_ref_ctx = ctx;
  325. if (flags & SPU_CREATE_AFFINITY_SPU) {
  326. if (list_empty(&neighbor->aff_list)) {
  327. list_add_tail(&neighbor->aff_list,
  328. &ctx->gang->aff_list_head);
  329. neighbor->aff_head = 1;
  330. }
  331. if (list_is_last(&neighbor->aff_list, &ctx->gang->aff_list_head)
  332. || list_entry(neighbor->aff_list.next, struct spu_context,
  333. aff_list)->aff_head) {
  334. list_add(&ctx->aff_list, &neighbor->aff_list);
  335. } else {
  336. list_add_tail(&ctx->aff_list, &neighbor->aff_list);
  337. if (neighbor->aff_head) {
  338. neighbor->aff_head = 0;
  339. ctx->aff_head = 1;
  340. }
  341. }
  342. if (!ctx->gang->aff_ref_ctx)
  343. ctx->gang->aff_ref_ctx = ctx;
  344. }
  345. }
  346. static int
  347. spufs_create_context(struct inode *inode, struct dentry *dentry,
  348. struct vfsmount *mnt, int flags, int mode,
  349. struct file *aff_filp)
  350. {
  351. int ret;
  352. int affinity;
  353. struct spu_gang *gang;
  354. struct spu_context *neighbor;
  355. ret = -EPERM;
  356. if ((flags & SPU_CREATE_NOSCHED) &&
  357. !capable(CAP_SYS_NICE))
  358. goto out_unlock;
  359. ret = -EINVAL;
  360. if ((flags & (SPU_CREATE_NOSCHED | SPU_CREATE_ISOLATE))
  361. == SPU_CREATE_ISOLATE)
  362. goto out_unlock;
  363. ret = -ENODEV;
  364. if ((flags & SPU_CREATE_ISOLATE) && !isolated_loader)
  365. goto out_unlock;
  366. gang = NULL;
  367. neighbor = NULL;
  368. affinity = flags & (SPU_CREATE_AFFINITY_MEM | SPU_CREATE_AFFINITY_SPU);
  369. if (affinity) {
  370. gang = SPUFS_I(inode)->i_gang;
  371. ret = -EINVAL;
  372. if (!gang)
  373. goto out_unlock;
  374. mutex_lock(&gang->aff_mutex);
  375. neighbor = spufs_assert_affinity(flags, gang, aff_filp);
  376. if (IS_ERR(neighbor)) {
  377. ret = PTR_ERR(neighbor);
  378. goto out_aff_unlock;
  379. }
  380. }
  381. ret = spufs_mkdir(inode, dentry, flags, mode & S_IRWXUGO);
  382. if (ret)
  383. goto out_aff_unlock;
  384. if (affinity)
  385. spufs_set_affinity(flags, SPUFS_I(dentry->d_inode)->i_ctx,
  386. neighbor);
  387. /*
  388. * get references for dget and mntget, will be released
  389. * in error path of *_open().
  390. */
  391. ret = spufs_context_open(dget(dentry), mntget(mnt));
  392. if (ret < 0) {
  393. WARN_ON(spufs_rmdir(inode, dentry));
  394. mutex_unlock(&inode->i_mutex);
  395. spu_forget(SPUFS_I(dentry->d_inode)->i_ctx);
  396. goto out;
  397. }
  398. out_aff_unlock:
  399. if (affinity)
  400. mutex_unlock(&gang->aff_mutex);
  401. out_unlock:
  402. mutex_unlock(&inode->i_mutex);
  403. out:
  404. dput(dentry);
  405. return ret;
  406. }
  407. static int
  408. spufs_mkgang(struct inode *dir, struct dentry *dentry, int mode)
  409. {
  410. int ret;
  411. struct inode *inode;
  412. struct spu_gang *gang;
  413. ret = -ENOSPC;
  414. inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
  415. if (!inode)
  416. goto out;
  417. ret = 0;
  418. if (dir->i_mode & S_ISGID) {
  419. inode->i_gid = dir->i_gid;
  420. inode->i_mode &= S_ISGID;
  421. }
  422. gang = alloc_spu_gang();
  423. SPUFS_I(inode)->i_ctx = NULL;
  424. SPUFS_I(inode)->i_gang = gang;
  425. if (!gang)
  426. goto out_iput;
  427. inode->i_op = &simple_dir_inode_operations;
  428. inode->i_fop = &simple_dir_operations;
  429. d_instantiate(dentry, inode);
  430. dir->i_nlink++;
  431. dentry->d_inode->i_nlink++;
  432. return ret;
  433. out_iput:
  434. iput(inode);
  435. out:
  436. return ret;
  437. }
  438. static int spufs_gang_open(struct dentry *dentry, struct vfsmount *mnt)
  439. {
  440. int ret;
  441. struct file *filp;
  442. ret = get_unused_fd();
  443. if (ret < 0) {
  444. dput(dentry);
  445. mntput(mnt);
  446. goto out;
  447. }
  448. filp = dentry_open(dentry, mnt, O_RDONLY);
  449. if (IS_ERR(filp)) {
  450. put_unused_fd(ret);
  451. ret = PTR_ERR(filp);
  452. goto out;
  453. }
  454. filp->f_op = &simple_dir_operations;
  455. fd_install(ret, filp);
  456. out:
  457. return ret;
  458. }
  459. static int spufs_create_gang(struct inode *inode,
  460. struct dentry *dentry,
  461. struct vfsmount *mnt, int mode)
  462. {
  463. int ret;
  464. ret = spufs_mkgang(inode, dentry, mode & S_IRWXUGO);
  465. if (ret)
  466. goto out;
  467. /*
  468. * get references for dget and mntget, will be released
  469. * in error path of *_open().
  470. */
  471. ret = spufs_gang_open(dget(dentry), mntget(mnt));
  472. if (ret < 0) {
  473. int err = simple_rmdir(inode, dentry);
  474. WARN_ON(err);
  475. }
  476. out:
  477. mutex_unlock(&inode->i_mutex);
  478. dput(dentry);
  479. return ret;
  480. }
  481. static struct file_system_type spufs_type;
  482. long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode,
  483. struct file *filp)
  484. {
  485. struct dentry *dentry;
  486. int ret;
  487. ret = -EINVAL;
  488. /* check if we are on spufs */
  489. if (nd->dentry->d_sb->s_type != &spufs_type)
  490. goto out;
  491. /* don't accept undefined flags */
  492. if (flags & (~SPU_CREATE_FLAG_ALL))
  493. goto out;
  494. /* only threads can be underneath a gang */
  495. if (nd->dentry != nd->dentry->d_sb->s_root) {
  496. if ((flags & SPU_CREATE_GANG) ||
  497. !SPUFS_I(nd->dentry->d_inode)->i_gang)
  498. goto out;
  499. }
  500. dentry = lookup_create(nd, 1);
  501. ret = PTR_ERR(dentry);
  502. if (IS_ERR(dentry))
  503. goto out_dir;
  504. ret = -EEXIST;
  505. if (dentry->d_inode)
  506. goto out_dput;
  507. mode &= ~current->fs->umask;
  508. if (flags & SPU_CREATE_GANG)
  509. return spufs_create_gang(nd->dentry->d_inode,
  510. dentry, nd->mnt, mode);
  511. else
  512. return spufs_create_context(nd->dentry->d_inode,
  513. dentry, nd->mnt, flags, mode, filp);
  514. out_dput:
  515. dput(dentry);
  516. out_dir:
  517. mutex_unlock(&nd->dentry->d_inode->i_mutex);
  518. out:
  519. return ret;
  520. }
  521. /* File system initialization */
  522. enum {
  523. Opt_uid, Opt_gid, Opt_mode, Opt_err,
  524. };
  525. static match_table_t spufs_tokens = {
  526. { Opt_uid, "uid=%d" },
  527. { Opt_gid, "gid=%d" },
  528. { Opt_mode, "mode=%o" },
  529. { Opt_err, NULL },
  530. };
  531. static int
  532. spufs_parse_options(char *options, struct inode *root)
  533. {
  534. char *p;
  535. substring_t args[MAX_OPT_ARGS];
  536. while ((p = strsep(&options, ",")) != NULL) {
  537. int token, option;
  538. if (!*p)
  539. continue;
  540. token = match_token(p, spufs_tokens, args);
  541. switch (token) {
  542. case Opt_uid:
  543. if (match_int(&args[0], &option))
  544. return 0;
  545. root->i_uid = option;
  546. break;
  547. case Opt_gid:
  548. if (match_int(&args[0], &option))
  549. return 0;
  550. root->i_gid = option;
  551. break;
  552. case Opt_mode:
  553. if (match_octal(&args[0], &option))
  554. return 0;
  555. root->i_mode = option | S_IFDIR;
  556. break;
  557. default:
  558. return 0;
  559. }
  560. }
  561. return 1;
  562. }
  563. static void spufs_exit_isolated_loader(void)
  564. {
  565. kfree(isolated_loader);
  566. }
  567. static void
  568. spufs_init_isolated_loader(void)
  569. {
  570. struct device_node *dn;
  571. const char *loader;
  572. int size;
  573. dn = of_find_node_by_path("/spu-isolation");
  574. if (!dn)
  575. return;
  576. loader = of_get_property(dn, "loader", &size);
  577. if (!loader)
  578. return;
  579. /* kmalloc should align on a 16 byte boundary..* */
  580. isolated_loader = kmalloc(size, GFP_KERNEL);
  581. if (!isolated_loader)
  582. return;
  583. memcpy(isolated_loader, loader, size);
  584. printk(KERN_INFO "spufs: SPU isolation mode enabled\n");
  585. }
  586. static int
  587. spufs_create_root(struct super_block *sb, void *data)
  588. {
  589. struct inode *inode;
  590. int ret;
  591. ret = -ENODEV;
  592. if (!spu_management_ops)
  593. goto out;
  594. ret = -ENOMEM;
  595. inode = spufs_new_inode(sb, S_IFDIR | 0775);
  596. if (!inode)
  597. goto out;
  598. inode->i_op = &simple_dir_inode_operations;
  599. inode->i_fop = &simple_dir_operations;
  600. SPUFS_I(inode)->i_ctx = NULL;
  601. ret = -EINVAL;
  602. if (!spufs_parse_options(data, inode))
  603. goto out_iput;
  604. ret = -ENOMEM;
  605. sb->s_root = d_alloc_root(inode);
  606. if (!sb->s_root)
  607. goto out_iput;
  608. return 0;
  609. out_iput:
  610. iput(inode);
  611. out:
  612. return ret;
  613. }
  614. static int
  615. spufs_fill_super(struct super_block *sb, void *data, int silent)
  616. {
  617. static struct super_operations s_ops = {
  618. .alloc_inode = spufs_alloc_inode,
  619. .destroy_inode = spufs_destroy_inode,
  620. .statfs = simple_statfs,
  621. .delete_inode = spufs_delete_inode,
  622. .drop_inode = generic_delete_inode,
  623. };
  624. sb->s_maxbytes = MAX_LFS_FILESIZE;
  625. sb->s_blocksize = PAGE_CACHE_SIZE;
  626. sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
  627. sb->s_magic = SPUFS_MAGIC;
  628. sb->s_op = &s_ops;
  629. return spufs_create_root(sb, data);
  630. }
  631. static int
  632. spufs_get_sb(struct file_system_type *fstype, int flags,
  633. const char *name, void *data, struct vfsmount *mnt)
  634. {
  635. return get_sb_single(fstype, flags, data, spufs_fill_super, mnt);
  636. }
  637. static struct file_system_type spufs_type = {
  638. .owner = THIS_MODULE,
  639. .name = "spufs",
  640. .get_sb = spufs_get_sb,
  641. .kill_sb = kill_litter_super,
  642. };
  643. static int __init spufs_init(void)
  644. {
  645. int ret;
  646. ret = -ENODEV;
  647. if (!spu_management_ops)
  648. goto out;
  649. ret = -ENOMEM;
  650. spufs_inode_cache = kmem_cache_create("spufs_inode_cache",
  651. sizeof(struct spufs_inode_info), 0,
  652. SLAB_HWCACHE_ALIGN, spufs_init_once);
  653. if (!spufs_inode_cache)
  654. goto out;
  655. ret = spu_sched_init();
  656. if (ret)
  657. goto out_cache;
  658. ret = register_filesystem(&spufs_type);
  659. if (ret)
  660. goto out_sched;
  661. ret = register_spu_syscalls(&spufs_calls);
  662. if (ret)
  663. goto out_fs;
  664. ret = register_arch_coredump_calls(&spufs_coredump_calls);
  665. if (ret)
  666. goto out_syscalls;
  667. spufs_init_isolated_loader();
  668. return 0;
  669. out_syscalls:
  670. unregister_spu_syscalls(&spufs_calls);
  671. out_fs:
  672. unregister_filesystem(&spufs_type);
  673. out_sched:
  674. spu_sched_exit();
  675. out_cache:
  676. kmem_cache_destroy(spufs_inode_cache);
  677. out:
  678. return ret;
  679. }
  680. module_init(spufs_init);
  681. static void __exit spufs_exit(void)
  682. {
  683. spu_sched_exit();
  684. spufs_exit_isolated_loader();
  685. unregister_arch_coredump_calls(&spufs_coredump_calls);
  686. unregister_spu_syscalls(&spufs_calls);
  687. unregister_filesystem(&spufs_type);
  688. kmem_cache_destroy(spufs_inode_cache);
  689. }
  690. module_exit(spufs_exit);
  691. MODULE_LICENSE("GPL");
  692. MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");