inode.c 18 KB

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