inode.c 18 KB

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