inode.c 18 KB

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