inode.c 17 KB

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