inode.c 18 KB

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