inode.c 18 KB

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