inode.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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/spu_priv1.h>
  36. #include <asm/io.h>
  37. #include <asm/semaphore.h>
  38. #include <asm/spu.h>
  39. #include <asm/uaccess.h>
  40. #include "spufs.h"
  41. static kmem_cache_t *spufs_inode_cache;
  42. static char *isolated_loader;
  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, SLAB_KERNEL);
  48. if (!ei)
  49. return NULL;
  50. ei->i_gang = NULL;
  51. ei->i_ctx = NULL;
  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, kmem_cache_t * cachep, unsigned long flags)
  61. {
  62. struct spufs_inode_info *ei = p;
  63. if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
  64. SLAB_CTOR_CONSTRUCTOR) {
  65. inode_init_once(&ei->vfs_inode);
  66. }
  67. }
  68. static struct inode *
  69. spufs_new_inode(struct super_block *sb, int mode)
  70. {
  71. struct inode *inode;
  72. inode = new_inode(sb);
  73. if (!inode)
  74. goto out;
  75. inode->i_mode = mode;
  76. inode->i_uid = current->fsuid;
  77. inode->i_gid = current->fsgid;
  78. inode->i_blocks = 0;
  79. inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  80. out:
  81. return inode;
  82. }
  83. static int
  84. spufs_setattr(struct dentry *dentry, struct iattr *attr)
  85. {
  86. struct inode *inode = dentry->d_inode;
  87. if ((attr->ia_valid & ATTR_SIZE) &&
  88. (attr->ia_size != inode->i_size))
  89. return -EINVAL;
  90. return inode_setattr(inode, attr);
  91. }
  92. static int
  93. spufs_new_file(struct super_block *sb, struct dentry *dentry,
  94. const struct file_operations *fops, int mode,
  95. struct spu_context *ctx)
  96. {
  97. static struct inode_operations spufs_file_iops = {
  98. .setattr = spufs_setattr,
  99. };
  100. struct inode *inode;
  101. int ret;
  102. ret = -ENOSPC;
  103. inode = spufs_new_inode(sb, S_IFREG | mode);
  104. if (!inode)
  105. goto out;
  106. ret = 0;
  107. inode->i_op = &spufs_file_iops;
  108. inode->i_fop = fops;
  109. inode->i_private = SPUFS_I(inode)->i_ctx = get_spu_context(ctx);
  110. d_add(dentry, inode);
  111. out:
  112. return ret;
  113. }
  114. static void
  115. spufs_delete_inode(struct inode *inode)
  116. {
  117. struct spufs_inode_info *ei = SPUFS_I(inode);
  118. if (ei->i_ctx)
  119. put_spu_context(ei->i_ctx);
  120. if (ei->i_gang)
  121. put_spu_gang(ei->i_gang);
  122. clear_inode(inode);
  123. }
  124. static void spufs_prune_dir(struct dentry *dir)
  125. {
  126. struct dentry *dentry, *tmp;
  127. mutex_lock(&dir->d_inode->i_mutex);
  128. list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
  129. spin_lock(&dcache_lock);
  130. spin_lock(&dentry->d_lock);
  131. if (!(d_unhashed(dentry)) && dentry->d_inode) {
  132. dget_locked(dentry);
  133. __d_drop(dentry);
  134. spin_unlock(&dentry->d_lock);
  135. simple_unlink(dir->d_inode, dentry);
  136. spin_unlock(&dcache_lock);
  137. dput(dentry);
  138. } else {
  139. spin_unlock(&dentry->d_lock);
  140. spin_unlock(&dcache_lock);
  141. }
  142. }
  143. shrink_dcache_parent(dir);
  144. mutex_unlock(&dir->d_inode->i_mutex);
  145. }
  146. /* Caller must hold parent->i_mutex */
  147. static int spufs_rmdir(struct inode *parent, struct dentry *dir)
  148. {
  149. /* remove all entries */
  150. spufs_prune_dir(dir);
  151. return simple_rmdir(parent, dir);
  152. }
  153. static int spufs_fill_dir(struct dentry *dir, struct tree_descr *files,
  154. int mode, struct spu_context *ctx)
  155. {
  156. struct dentry *dentry;
  157. int ret;
  158. while (files->name && files->name[0]) {
  159. ret = -ENOMEM;
  160. dentry = d_alloc_name(dir, files->name);
  161. if (!dentry)
  162. goto out;
  163. ret = spufs_new_file(dir->d_sb, dentry, files->ops,
  164. files->mode & mode, ctx);
  165. if (ret)
  166. goto out;
  167. files++;
  168. }
  169. return 0;
  170. out:
  171. spufs_prune_dir(dir);
  172. return ret;
  173. }
  174. static int spufs_dir_close(struct inode *inode, struct file *file)
  175. {
  176. struct spu_context *ctx;
  177. struct inode *parent;
  178. struct dentry *dir;
  179. int ret;
  180. dir = file->f_dentry;
  181. parent = dir->d_parent->d_inode;
  182. ctx = SPUFS_I(dir->d_inode)->i_ctx;
  183. mutex_lock(&parent->i_mutex);
  184. ret = spufs_rmdir(parent, dir);
  185. mutex_unlock(&parent->i_mutex);
  186. WARN_ON(ret);
  187. /* We have to give up the mm_struct */
  188. spu_forget(ctx);
  189. return dcache_dir_close(inode, file);
  190. }
  191. struct inode_operations spufs_dir_inode_operations = {
  192. .lookup = simple_lookup,
  193. };
  194. struct file_operations spufs_context_fops = {
  195. .open = dcache_dir_open,
  196. .release = spufs_dir_close,
  197. .llseek = dcache_dir_lseek,
  198. .read = generic_read_dir,
  199. .readdir = dcache_readdir,
  200. .fsync = simple_sync_file,
  201. };
  202. static int spu_setup_isolated(struct spu_context *ctx)
  203. {
  204. int ret;
  205. u64 __iomem *mfc_cntl;
  206. u64 sr1;
  207. u32 status;
  208. unsigned long timeout;
  209. const u32 status_loading = SPU_STATUS_RUNNING
  210. | SPU_STATUS_ISOLATED_STATE | SPU_STATUS_ISOLATED_LOAD_STATUS;
  211. if (!isolated_loader)
  212. return -ENODEV;
  213. /* prevent concurrent operation with spu_run */
  214. down(&ctx->run_sema);
  215. ctx->ops->master_start(ctx);
  216. ret = spu_acquire_exclusive(ctx);
  217. if (ret)
  218. goto out;
  219. mfc_cntl = &ctx->spu->priv2->mfc_control_RW;
  220. /* purge the MFC DMA queue to ensure no spurious accesses before we
  221. * enter kernel mode */
  222. timeout = jiffies + HZ;
  223. out_be64(mfc_cntl, MFC_CNTL_PURGE_DMA_REQUEST);
  224. while ((in_be64(mfc_cntl) & MFC_CNTL_PURGE_DMA_STATUS_MASK)
  225. != MFC_CNTL_PURGE_DMA_COMPLETE) {
  226. if (time_after(jiffies, timeout)) {
  227. printk(KERN_ERR "%s: timeout flushing MFC DMA queue\n",
  228. __FUNCTION__);
  229. ret = -EIO;
  230. goto out_unlock;
  231. }
  232. cond_resched();
  233. }
  234. /* put the SPE in kernel mode to allow access to the loader */
  235. sr1 = spu_mfc_sr1_get(ctx->spu);
  236. sr1 &= ~MFC_STATE1_PROBLEM_STATE_MASK;
  237. spu_mfc_sr1_set(ctx->spu, sr1);
  238. /* start the loader */
  239. ctx->ops->signal1_write(ctx, (unsigned long)isolated_loader >> 32);
  240. ctx->ops->signal2_write(ctx,
  241. (unsigned long)isolated_loader & 0xffffffff);
  242. ctx->ops->runcntl_write(ctx,
  243. SPU_RUNCNTL_RUNNABLE | SPU_RUNCNTL_ISOLATE);
  244. ret = 0;
  245. timeout = jiffies + HZ;
  246. while (((status = ctx->ops->status_read(ctx)) & status_loading) ==
  247. status_loading) {
  248. if (time_after(jiffies, timeout)) {
  249. printk(KERN_ERR "%s: timeout waiting for loader\n",
  250. __FUNCTION__);
  251. ret = -EIO;
  252. goto out_drop_priv;
  253. }
  254. cond_resched();
  255. }
  256. if (!(status & SPU_STATUS_RUNNING)) {
  257. /* If isolated LOAD has failed: run SPU, we will get a stop-and
  258. * signal later. */
  259. pr_debug("%s: isolated LOAD failed\n", __FUNCTION__);
  260. ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_RUNNABLE);
  261. ret = -EACCES;
  262. } else if (!(status & SPU_STATUS_ISOLATED_STATE)) {
  263. /* This isn't allowed by the CBEA, but check anyway */
  264. pr_debug("%s: SPU fell out of isolated mode?\n", __FUNCTION__);
  265. ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_STOP);
  266. ret = -EINVAL;
  267. }
  268. out_drop_priv:
  269. /* Finished accessing the loader. Drop kernel mode */
  270. sr1 |= MFC_STATE1_PROBLEM_STATE_MASK;
  271. spu_mfc_sr1_set(ctx->spu, sr1);
  272. out_unlock:
  273. spu_release_exclusive(ctx);
  274. out:
  275. ctx->ops->master_stop(ctx);
  276. up(&ctx->run_sema);
  277. return ret;
  278. }
  279. int spu_recycle_isolated(struct spu_context *ctx)
  280. {
  281. return spu_setup_isolated(ctx);
  282. }
  283. static int
  284. spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
  285. int mode)
  286. {
  287. int ret;
  288. struct inode *inode;
  289. struct spu_context *ctx;
  290. ret = -ENOSPC;
  291. inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
  292. if (!inode)
  293. goto out;
  294. if (dir->i_mode & S_ISGID) {
  295. inode->i_gid = dir->i_gid;
  296. inode->i_mode &= S_ISGID;
  297. }
  298. ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */
  299. SPUFS_I(inode)->i_ctx = ctx;
  300. if (!ctx)
  301. goto out_iput;
  302. ctx->flags = flags;
  303. inode->i_op = &spufs_dir_inode_operations;
  304. inode->i_fop = &simple_dir_operations;
  305. if (flags & SPU_CREATE_NOSCHED)
  306. ret = spufs_fill_dir(dentry, spufs_dir_nosched_contents,
  307. mode, ctx);
  308. else
  309. ret = spufs_fill_dir(dentry, spufs_dir_contents, mode, ctx);
  310. if (ret)
  311. goto out_free_ctx;
  312. d_instantiate(dentry, inode);
  313. dget(dentry);
  314. dir->i_nlink++;
  315. dentry->d_inode->i_nlink++;
  316. goto out;
  317. out_free_ctx:
  318. put_spu_context(ctx);
  319. out_iput:
  320. iput(inode);
  321. out:
  322. return ret;
  323. }
  324. static int spufs_context_open(struct dentry *dentry, struct vfsmount *mnt)
  325. {
  326. int ret;
  327. struct file *filp;
  328. ret = get_unused_fd();
  329. if (ret < 0) {
  330. dput(dentry);
  331. mntput(mnt);
  332. goto out;
  333. }
  334. filp = dentry_open(dentry, mnt, O_RDONLY);
  335. if (IS_ERR(filp)) {
  336. put_unused_fd(ret);
  337. ret = PTR_ERR(filp);
  338. goto out;
  339. }
  340. filp->f_op = &spufs_context_fops;
  341. fd_install(ret, filp);
  342. out:
  343. return ret;
  344. }
  345. static int spufs_create_context(struct inode *inode,
  346. struct dentry *dentry,
  347. struct vfsmount *mnt, int flags, int mode)
  348. {
  349. int ret;
  350. ret = -EPERM;
  351. if ((flags & SPU_CREATE_NOSCHED) &&
  352. !capable(CAP_SYS_NICE))
  353. goto out_unlock;
  354. ret = -EINVAL;
  355. if ((flags & (SPU_CREATE_NOSCHED | SPU_CREATE_ISOLATE))
  356. == SPU_CREATE_ISOLATE)
  357. goto out_unlock;
  358. ret = spufs_mkdir(inode, dentry, flags, mode & S_IRWXUGO);
  359. if (ret)
  360. goto out_unlock;
  361. /*
  362. * get references for dget and mntget, will be released
  363. * in error path of *_open().
  364. */
  365. ret = spufs_context_open(dget(dentry), mntget(mnt));
  366. if (ret < 0) {
  367. WARN_ON(spufs_rmdir(inode, dentry));
  368. mutex_unlock(&inode->i_mutex);
  369. spu_forget(SPUFS_I(dentry->d_inode)->i_ctx);
  370. goto out;
  371. }
  372. out_unlock:
  373. mutex_unlock(&inode->i_mutex);
  374. out:
  375. if (ret >= 0 && (flags & SPU_CREATE_ISOLATE)) {
  376. int setup_err = spu_setup_isolated(
  377. SPUFS_I(dentry->d_inode)->i_ctx);
  378. /* FIXME: clean up context again on failure to avoid
  379. leak. */
  380. if (setup_err)
  381. ret = setup_err;
  382. }
  383. dput(dentry);
  384. return ret;
  385. }
  386. static int spufs_rmgang(struct inode *root, struct dentry *dir)
  387. {
  388. /* FIXME: this fails if the dir is not empty,
  389. which causes a leak of gangs. */
  390. return simple_rmdir(root, dir);
  391. }
  392. static int spufs_gang_close(struct inode *inode, struct file *file)
  393. {
  394. struct inode *parent;
  395. struct dentry *dir;
  396. int ret;
  397. dir = file->f_dentry;
  398. parent = dir->d_parent->d_inode;
  399. ret = spufs_rmgang(parent, dir);
  400. WARN_ON(ret);
  401. return dcache_dir_close(inode, file);
  402. }
  403. struct file_operations spufs_gang_fops = {
  404. .open = dcache_dir_open,
  405. .release = spufs_gang_close,
  406. .llseek = dcache_dir_lseek,
  407. .read = generic_read_dir,
  408. .readdir = dcache_readdir,
  409. .fsync = simple_sync_file,
  410. };
  411. static int
  412. spufs_mkgang(struct inode *dir, struct dentry *dentry, int mode)
  413. {
  414. int ret;
  415. struct inode *inode;
  416. struct spu_gang *gang;
  417. ret = -ENOSPC;
  418. inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
  419. if (!inode)
  420. goto out;
  421. ret = 0;
  422. if (dir->i_mode & S_ISGID) {
  423. inode->i_gid = dir->i_gid;
  424. inode->i_mode &= S_ISGID;
  425. }
  426. gang = alloc_spu_gang();
  427. SPUFS_I(inode)->i_ctx = NULL;
  428. SPUFS_I(inode)->i_gang = gang;
  429. if (!gang)
  430. goto out_iput;
  431. inode->i_op = &spufs_dir_inode_operations;
  432. inode->i_fop = &simple_dir_operations;
  433. d_instantiate(dentry, inode);
  434. dget(dentry);
  435. dir->i_nlink++;
  436. dentry->d_inode->i_nlink++;
  437. return ret;
  438. out_iput:
  439. iput(inode);
  440. out:
  441. return ret;
  442. }
  443. static int spufs_gang_open(struct dentry *dentry, struct vfsmount *mnt)
  444. {
  445. int ret;
  446. struct file *filp;
  447. ret = get_unused_fd();
  448. if (ret < 0) {
  449. dput(dentry);
  450. mntput(mnt);
  451. goto out;
  452. }
  453. filp = dentry_open(dentry, mnt, O_RDONLY);
  454. if (IS_ERR(filp)) {
  455. put_unused_fd(ret);
  456. ret = PTR_ERR(filp);
  457. goto out;
  458. }
  459. filp->f_op = &spufs_gang_fops;
  460. fd_install(ret, filp);
  461. out:
  462. return ret;
  463. }
  464. static int spufs_create_gang(struct inode *inode,
  465. struct dentry *dentry,
  466. struct vfsmount *mnt, int mode)
  467. {
  468. int ret;
  469. ret = spufs_mkgang(inode, dentry, mode & S_IRWXUGO);
  470. if (ret)
  471. goto out;
  472. /*
  473. * get references for dget and mntget, will be released
  474. * in error path of *_open().
  475. */
  476. ret = spufs_gang_open(dget(dentry), mntget(mnt));
  477. if (ret < 0)
  478. WARN_ON(spufs_rmgang(inode, dentry));
  479. out:
  480. mutex_unlock(&inode->i_mutex);
  481. dput(dentry);
  482. return ret;
  483. }
  484. static struct file_system_type spufs_type;
  485. long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode)
  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);
  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_err,
  526. };
  527. static match_table_t spufs_tokens = {
  528. { Opt_uid, "uid=%d" },
  529. { Opt_gid, "gid=%d" },
  530. { Opt_err, NULL },
  531. };
  532. static int
  533. spufs_parse_options(char *options, struct inode *root)
  534. {
  535. char *p;
  536. substring_t args[MAX_OPT_ARGS];
  537. while ((p = strsep(&options, ",")) != NULL) {
  538. int token, option;
  539. if (!*p)
  540. continue;
  541. token = match_token(p, spufs_tokens, args);
  542. switch (token) {
  543. case Opt_uid:
  544. if (match_int(&args[0], &option))
  545. return 0;
  546. root->i_uid = option;
  547. break;
  548. case Opt_gid:
  549. if (match_int(&args[0], &option))
  550. return 0;
  551. root->i_gid = option;
  552. break;
  553. default:
  554. return 0;
  555. }
  556. }
  557. return 1;
  558. }
  559. static void
  560. spufs_init_isolated_loader(void)
  561. {
  562. struct device_node *dn;
  563. const char *loader;
  564. int size;
  565. dn = of_find_node_by_path("/spu-isolation");
  566. if (!dn)
  567. return;
  568. loader = get_property(dn, "loader", &size);
  569. if (!loader)
  570. return;
  571. /* kmalloc should align on a 16 byte boundary..* */
  572. isolated_loader = kmalloc(size, GFP_KERNEL);
  573. if (!isolated_loader)
  574. return;
  575. memcpy(isolated_loader, loader, size);
  576. printk(KERN_INFO "spufs: SPU isolation mode enabled\n");
  577. }
  578. static int
  579. spufs_create_root(struct super_block *sb, void *data)
  580. {
  581. struct inode *inode;
  582. int ret;
  583. ret = -ENOMEM;
  584. inode = spufs_new_inode(sb, S_IFDIR | 0775);
  585. if (!inode)
  586. goto out;
  587. inode->i_op = &spufs_dir_inode_operations;
  588. inode->i_fop = &simple_dir_operations;
  589. SPUFS_I(inode)->i_ctx = NULL;
  590. ret = -EINVAL;
  591. if (!spufs_parse_options(data, inode))
  592. goto out_iput;
  593. ret = -ENOMEM;
  594. sb->s_root = d_alloc_root(inode);
  595. if (!sb->s_root)
  596. goto out_iput;
  597. return 0;
  598. out_iput:
  599. iput(inode);
  600. out:
  601. return ret;
  602. }
  603. static int
  604. spufs_fill_super(struct super_block *sb, void *data, int silent)
  605. {
  606. static struct super_operations s_ops = {
  607. .alloc_inode = spufs_alloc_inode,
  608. .destroy_inode = spufs_destroy_inode,
  609. .statfs = simple_statfs,
  610. .delete_inode = spufs_delete_inode,
  611. .drop_inode = generic_delete_inode,
  612. };
  613. sb->s_maxbytes = MAX_LFS_FILESIZE;
  614. sb->s_blocksize = PAGE_CACHE_SIZE;
  615. sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
  616. sb->s_magic = SPUFS_MAGIC;
  617. sb->s_op = &s_ops;
  618. return spufs_create_root(sb, data);
  619. }
  620. static int
  621. spufs_get_sb(struct file_system_type *fstype, int flags,
  622. const char *name, void *data, struct vfsmount *mnt)
  623. {
  624. return get_sb_single(fstype, flags, data, spufs_fill_super, mnt);
  625. }
  626. static struct file_system_type spufs_type = {
  627. .owner = THIS_MODULE,
  628. .name = "spufs",
  629. .get_sb = spufs_get_sb,
  630. .kill_sb = kill_litter_super,
  631. };
  632. static int __init spufs_init(void)
  633. {
  634. int ret;
  635. ret = -ENOMEM;
  636. spufs_inode_cache = kmem_cache_create("spufs_inode_cache",
  637. sizeof(struct spufs_inode_info), 0,
  638. SLAB_HWCACHE_ALIGN, spufs_init_once, NULL);
  639. if (!spufs_inode_cache)
  640. goto out;
  641. if (spu_sched_init() != 0) {
  642. kmem_cache_destroy(spufs_inode_cache);
  643. goto out;
  644. }
  645. ret = register_filesystem(&spufs_type);
  646. if (ret)
  647. goto out_cache;
  648. ret = register_spu_syscalls(&spufs_calls);
  649. if (ret)
  650. goto out_fs;
  651. spufs_init_isolated_loader();
  652. return 0;
  653. out_fs:
  654. unregister_filesystem(&spufs_type);
  655. out_cache:
  656. kmem_cache_destroy(spufs_inode_cache);
  657. out:
  658. return ret;
  659. }
  660. module_init(spufs_init);
  661. static void __exit spufs_exit(void)
  662. {
  663. spu_sched_exit();
  664. unregister_spu_syscalls(&spufs_calls);
  665. unregister_filesystem(&spufs_type);
  666. kmem_cache_destroy(spufs_inode_cache);
  667. }
  668. module_exit(spufs_exit);
  669. MODULE_LICENSE("GPL");
  670. MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");