inode.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  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. setattr_copy(inode, attr);
  95. mark_inode_dirty(inode);
  96. return 0;
  97. }
  98. static int
  99. spufs_new_file(struct super_block *sb, struct dentry *dentry,
  100. const struct file_operations *fops, int mode,
  101. size_t size, struct spu_context *ctx)
  102. {
  103. static const struct inode_operations spufs_file_iops = {
  104. .setattr = spufs_setattr,
  105. };
  106. struct inode *inode;
  107. int ret;
  108. ret = -ENOSPC;
  109. inode = spufs_new_inode(sb, S_IFREG | mode);
  110. if (!inode)
  111. goto out;
  112. ret = 0;
  113. inode->i_op = &spufs_file_iops;
  114. inode->i_fop = fops;
  115. inode->i_size = size;
  116. inode->i_private = SPUFS_I(inode)->i_ctx = get_spu_context(ctx);
  117. d_add(dentry, inode);
  118. out:
  119. return ret;
  120. }
  121. static void
  122. spufs_evict_inode(struct inode *inode)
  123. {
  124. struct spufs_inode_info *ei = SPUFS_I(inode);
  125. end_writeback(inode);
  126. if (ei->i_ctx)
  127. put_spu_context(ei->i_ctx);
  128. if (ei->i_gang)
  129. put_spu_gang(ei->i_gang);
  130. }
  131. static void spufs_prune_dir(struct dentry *dir)
  132. {
  133. struct dentry *dentry, *tmp;
  134. mutex_lock(&dir->d_inode->i_mutex);
  135. list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
  136. spin_lock(&dcache_lock);
  137. spin_lock(&dentry->d_lock);
  138. if (!(d_unhashed(dentry)) && dentry->d_inode) {
  139. dget_locked_dlock(dentry);
  140. __d_drop(dentry);
  141. spin_unlock(&dentry->d_lock);
  142. simple_unlink(dir->d_inode, dentry);
  143. /* XXX: what is dcache_lock protecting here? Other
  144. * filesystems (IB, configfs) release dcache_lock
  145. * before unlink */
  146. spin_unlock(&dcache_lock);
  147. dput(dentry);
  148. } else {
  149. spin_unlock(&dentry->d_lock);
  150. spin_unlock(&dcache_lock);
  151. }
  152. }
  153. shrink_dcache_parent(dir);
  154. mutex_unlock(&dir->d_inode->i_mutex);
  155. }
  156. /* Caller must hold parent->i_mutex */
  157. static int spufs_rmdir(struct inode *parent, struct dentry *dir)
  158. {
  159. /* remove all entries */
  160. spufs_prune_dir(dir);
  161. d_drop(dir);
  162. return simple_rmdir(parent, dir);
  163. }
  164. static int spufs_fill_dir(struct dentry *dir,
  165. const struct spufs_tree_descr *files, int mode,
  166. struct spu_context *ctx)
  167. {
  168. struct dentry *dentry, *tmp;
  169. int ret;
  170. while (files->name && files->name[0]) {
  171. ret = -ENOMEM;
  172. dentry = d_alloc_name(dir, files->name);
  173. if (!dentry)
  174. goto out;
  175. ret = spufs_new_file(dir->d_sb, dentry, files->ops,
  176. files->mode & mode, files->size, ctx);
  177. if (ret)
  178. goto out;
  179. files++;
  180. }
  181. return 0;
  182. out:
  183. /*
  184. * remove all children from dir. dir->inode is not set so don't
  185. * just simply use spufs_prune_dir() and panic afterwards :)
  186. * dput() looks like it will do the right thing:
  187. * - dec parent's ref counter
  188. * - remove child from parent's child list
  189. * - free child's inode if possible
  190. * - free child
  191. */
  192. list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
  193. dput(dentry);
  194. }
  195. shrink_dcache_parent(dir);
  196. return ret;
  197. }
  198. static int spufs_dir_close(struct inode *inode, struct file *file)
  199. {
  200. struct spu_context *ctx;
  201. struct inode *parent;
  202. struct dentry *dir;
  203. int ret;
  204. dir = file->f_path.dentry;
  205. parent = dir->d_parent->d_inode;
  206. ctx = SPUFS_I(dir->d_inode)->i_ctx;
  207. mutex_lock_nested(&parent->i_mutex, I_MUTEX_PARENT);
  208. ret = spufs_rmdir(parent, dir);
  209. mutex_unlock(&parent->i_mutex);
  210. WARN_ON(ret);
  211. /* We have to give up the mm_struct */
  212. spu_forget(ctx);
  213. return dcache_dir_close(inode, file);
  214. }
  215. const struct file_operations spufs_context_fops = {
  216. .open = dcache_dir_open,
  217. .release = spufs_dir_close,
  218. .llseek = dcache_dir_lseek,
  219. .read = generic_read_dir,
  220. .readdir = dcache_readdir,
  221. .fsync = noop_fsync,
  222. };
  223. EXPORT_SYMBOL_GPL(spufs_context_fops);
  224. static int
  225. spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
  226. int mode)
  227. {
  228. int ret;
  229. struct inode *inode;
  230. struct spu_context *ctx;
  231. ret = -ENOSPC;
  232. inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
  233. if (!inode)
  234. goto out;
  235. if (dir->i_mode & S_ISGID) {
  236. inode->i_gid = dir->i_gid;
  237. inode->i_mode &= S_ISGID;
  238. }
  239. ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */
  240. SPUFS_I(inode)->i_ctx = ctx;
  241. if (!ctx)
  242. goto out_iput;
  243. ctx->flags = flags;
  244. inode->i_op = &simple_dir_inode_operations;
  245. inode->i_fop = &simple_dir_operations;
  246. if (flags & SPU_CREATE_NOSCHED)
  247. ret = spufs_fill_dir(dentry, spufs_dir_nosched_contents,
  248. mode, ctx);
  249. else
  250. ret = spufs_fill_dir(dentry, spufs_dir_contents, mode, ctx);
  251. if (ret)
  252. goto out_free_ctx;
  253. if (spufs_get_sb_info(dir->i_sb)->debug)
  254. ret = spufs_fill_dir(dentry, spufs_dir_debug_contents,
  255. mode, ctx);
  256. if (ret)
  257. goto out_free_ctx;
  258. d_instantiate(dentry, inode);
  259. dget(dentry);
  260. inc_nlink(dir);
  261. inc_nlink(dentry->d_inode);
  262. goto out;
  263. out_free_ctx:
  264. spu_forget(ctx);
  265. put_spu_context(ctx);
  266. out_iput:
  267. iput(inode);
  268. out:
  269. return ret;
  270. }
  271. static int spufs_context_open(struct dentry *dentry, struct vfsmount *mnt)
  272. {
  273. int ret;
  274. struct file *filp;
  275. ret = get_unused_fd();
  276. if (ret < 0) {
  277. dput(dentry);
  278. mntput(mnt);
  279. goto out;
  280. }
  281. filp = dentry_open(dentry, mnt, O_RDONLY, current_cred());
  282. if (IS_ERR(filp)) {
  283. put_unused_fd(ret);
  284. ret = PTR_ERR(filp);
  285. goto out;
  286. }
  287. filp->f_op = &spufs_context_fops;
  288. fd_install(ret, filp);
  289. out:
  290. return ret;
  291. }
  292. static struct spu_context *
  293. spufs_assert_affinity(unsigned int flags, struct spu_gang *gang,
  294. struct file *filp)
  295. {
  296. struct spu_context *tmp, *neighbor, *err;
  297. int count, node;
  298. int aff_supp;
  299. aff_supp = !list_empty(&(list_entry(cbe_spu_info[0].spus.next,
  300. struct spu, cbe_list))->aff_list);
  301. if (!aff_supp)
  302. return ERR_PTR(-EINVAL);
  303. if (flags & SPU_CREATE_GANG)
  304. return ERR_PTR(-EINVAL);
  305. if (flags & SPU_CREATE_AFFINITY_MEM &&
  306. gang->aff_ref_ctx &&
  307. gang->aff_ref_ctx->flags & SPU_CREATE_AFFINITY_MEM)
  308. return ERR_PTR(-EEXIST);
  309. if (gang->aff_flags & AFF_MERGED)
  310. return ERR_PTR(-EBUSY);
  311. neighbor = NULL;
  312. if (flags & SPU_CREATE_AFFINITY_SPU) {
  313. if (!filp || filp->f_op != &spufs_context_fops)
  314. return ERR_PTR(-EINVAL);
  315. neighbor = get_spu_context(
  316. SPUFS_I(filp->f_dentry->d_inode)->i_ctx);
  317. if (!list_empty(&neighbor->aff_list) && !(neighbor->aff_head) &&
  318. !list_is_last(&neighbor->aff_list, &gang->aff_list_head) &&
  319. !list_entry(neighbor->aff_list.next, struct spu_context,
  320. aff_list)->aff_head) {
  321. err = ERR_PTR(-EEXIST);
  322. goto out_put_neighbor;
  323. }
  324. if (gang != neighbor->gang) {
  325. err = ERR_PTR(-EINVAL);
  326. goto out_put_neighbor;
  327. }
  328. count = 1;
  329. list_for_each_entry(tmp, &gang->aff_list_head, aff_list)
  330. count++;
  331. if (list_empty(&neighbor->aff_list))
  332. count++;
  333. for (node = 0; node < MAX_NUMNODES; node++) {
  334. if ((cbe_spu_info[node].n_spus - atomic_read(
  335. &cbe_spu_info[node].reserved_spus)) >= count)
  336. break;
  337. }
  338. if (node == MAX_NUMNODES) {
  339. err = ERR_PTR(-EEXIST);
  340. goto out_put_neighbor;
  341. }
  342. }
  343. return neighbor;
  344. out_put_neighbor:
  345. put_spu_context(neighbor);
  346. return err;
  347. }
  348. static void
  349. spufs_set_affinity(unsigned int flags, struct spu_context *ctx,
  350. struct spu_context *neighbor)
  351. {
  352. if (flags & SPU_CREATE_AFFINITY_MEM)
  353. ctx->gang->aff_ref_ctx = ctx;
  354. if (flags & SPU_CREATE_AFFINITY_SPU) {
  355. if (list_empty(&neighbor->aff_list)) {
  356. list_add_tail(&neighbor->aff_list,
  357. &ctx->gang->aff_list_head);
  358. neighbor->aff_head = 1;
  359. }
  360. if (list_is_last(&neighbor->aff_list, &ctx->gang->aff_list_head)
  361. || list_entry(neighbor->aff_list.next, struct spu_context,
  362. aff_list)->aff_head) {
  363. list_add(&ctx->aff_list, &neighbor->aff_list);
  364. } else {
  365. list_add_tail(&ctx->aff_list, &neighbor->aff_list);
  366. if (neighbor->aff_head) {
  367. neighbor->aff_head = 0;
  368. ctx->aff_head = 1;
  369. }
  370. }
  371. if (!ctx->gang->aff_ref_ctx)
  372. ctx->gang->aff_ref_ctx = ctx;
  373. }
  374. }
  375. static int
  376. spufs_create_context(struct inode *inode, struct dentry *dentry,
  377. struct vfsmount *mnt, int flags, int mode,
  378. struct file *aff_filp)
  379. {
  380. int ret;
  381. int affinity;
  382. struct spu_gang *gang;
  383. struct spu_context *neighbor;
  384. ret = -EPERM;
  385. if ((flags & SPU_CREATE_NOSCHED) &&
  386. !capable(CAP_SYS_NICE))
  387. goto out_unlock;
  388. ret = -EINVAL;
  389. if ((flags & (SPU_CREATE_NOSCHED | SPU_CREATE_ISOLATE))
  390. == SPU_CREATE_ISOLATE)
  391. goto out_unlock;
  392. ret = -ENODEV;
  393. if ((flags & SPU_CREATE_ISOLATE) && !isolated_loader)
  394. goto out_unlock;
  395. gang = NULL;
  396. neighbor = NULL;
  397. affinity = flags & (SPU_CREATE_AFFINITY_MEM | SPU_CREATE_AFFINITY_SPU);
  398. if (affinity) {
  399. gang = SPUFS_I(inode)->i_gang;
  400. ret = -EINVAL;
  401. if (!gang)
  402. goto out_unlock;
  403. mutex_lock(&gang->aff_mutex);
  404. neighbor = spufs_assert_affinity(flags, gang, aff_filp);
  405. if (IS_ERR(neighbor)) {
  406. ret = PTR_ERR(neighbor);
  407. goto out_aff_unlock;
  408. }
  409. }
  410. ret = spufs_mkdir(inode, dentry, flags, mode & S_IRWXUGO);
  411. if (ret)
  412. goto out_aff_unlock;
  413. if (affinity) {
  414. spufs_set_affinity(flags, SPUFS_I(dentry->d_inode)->i_ctx,
  415. neighbor);
  416. if (neighbor)
  417. put_spu_context(neighbor);
  418. }
  419. /*
  420. * get references for dget and mntget, will be released
  421. * in error path of *_open().
  422. */
  423. ret = spufs_context_open(dget(dentry), mntget(mnt));
  424. if (ret < 0) {
  425. WARN_ON(spufs_rmdir(inode, dentry));
  426. if (affinity)
  427. mutex_unlock(&gang->aff_mutex);
  428. mutex_unlock(&inode->i_mutex);
  429. spu_forget(SPUFS_I(dentry->d_inode)->i_ctx);
  430. goto out;
  431. }
  432. out_aff_unlock:
  433. if (affinity)
  434. mutex_unlock(&gang->aff_mutex);
  435. out_unlock:
  436. mutex_unlock(&inode->i_mutex);
  437. out:
  438. dput(dentry);
  439. return ret;
  440. }
  441. static int
  442. spufs_mkgang(struct inode *dir, struct dentry *dentry, int mode)
  443. {
  444. int ret;
  445. struct inode *inode;
  446. struct spu_gang *gang;
  447. ret = -ENOSPC;
  448. inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
  449. if (!inode)
  450. goto out;
  451. ret = 0;
  452. if (dir->i_mode & S_ISGID) {
  453. inode->i_gid = dir->i_gid;
  454. inode->i_mode &= S_ISGID;
  455. }
  456. gang = alloc_spu_gang();
  457. SPUFS_I(inode)->i_ctx = NULL;
  458. SPUFS_I(inode)->i_gang = gang;
  459. if (!gang)
  460. goto out_iput;
  461. inode->i_op = &simple_dir_inode_operations;
  462. inode->i_fop = &simple_dir_operations;
  463. d_instantiate(dentry, inode);
  464. inc_nlink(dir);
  465. inc_nlink(dentry->d_inode);
  466. return ret;
  467. out_iput:
  468. iput(inode);
  469. out:
  470. return ret;
  471. }
  472. static int spufs_gang_open(struct dentry *dentry, struct vfsmount *mnt)
  473. {
  474. int ret;
  475. struct file *filp;
  476. ret = get_unused_fd();
  477. if (ret < 0) {
  478. dput(dentry);
  479. mntput(mnt);
  480. goto out;
  481. }
  482. filp = dentry_open(dentry, mnt, O_RDONLY, current_cred());
  483. if (IS_ERR(filp)) {
  484. put_unused_fd(ret);
  485. ret = PTR_ERR(filp);
  486. goto out;
  487. }
  488. filp->f_op = &simple_dir_operations;
  489. fd_install(ret, filp);
  490. out:
  491. return ret;
  492. }
  493. static int spufs_create_gang(struct inode *inode,
  494. struct dentry *dentry,
  495. struct vfsmount *mnt, int mode)
  496. {
  497. int ret;
  498. ret = spufs_mkgang(inode, dentry, mode & S_IRWXUGO);
  499. if (ret)
  500. goto out;
  501. /*
  502. * get references for dget and mntget, will be released
  503. * in error path of *_open().
  504. */
  505. ret = spufs_gang_open(dget(dentry), mntget(mnt));
  506. if (ret < 0) {
  507. int err = simple_rmdir(inode, dentry);
  508. WARN_ON(err);
  509. }
  510. out:
  511. mutex_unlock(&inode->i_mutex);
  512. dput(dentry);
  513. return ret;
  514. }
  515. static struct file_system_type spufs_type;
  516. long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode,
  517. struct file *filp)
  518. {
  519. struct dentry *dentry;
  520. int ret;
  521. ret = -EINVAL;
  522. /* check if we are on spufs */
  523. if (nd->path.dentry->d_sb->s_type != &spufs_type)
  524. goto out;
  525. /* don't accept undefined flags */
  526. if (flags & (~SPU_CREATE_FLAG_ALL))
  527. goto out;
  528. /* only threads can be underneath a gang */
  529. if (nd->path.dentry != nd->path.dentry->d_sb->s_root) {
  530. if ((flags & SPU_CREATE_GANG) ||
  531. !SPUFS_I(nd->path.dentry->d_inode)->i_gang)
  532. goto out;
  533. }
  534. dentry = lookup_create(nd, 1);
  535. ret = PTR_ERR(dentry);
  536. if (IS_ERR(dentry))
  537. goto out_dir;
  538. mode &= ~current_umask();
  539. if (flags & SPU_CREATE_GANG)
  540. ret = spufs_create_gang(nd->path.dentry->d_inode,
  541. dentry, nd->path.mnt, mode);
  542. else
  543. ret = spufs_create_context(nd->path.dentry->d_inode,
  544. dentry, nd->path.mnt, flags, mode,
  545. filp);
  546. if (ret >= 0)
  547. fsnotify_mkdir(nd->path.dentry->d_inode, dentry);
  548. return ret;
  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 const struct super_operations s_ops = {
  659. .alloc_inode = spufs_alloc_inode,
  660. .destroy_inode = spufs_destroy_inode,
  661. .statfs = simple_statfs,
  662. .evict_inode = spufs_evict_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 struct dentry *
  678. spufs_mount(struct file_system_type *fstype, int flags,
  679. const char *name, void *data)
  680. {
  681. return mount_single(fstype, flags, data, spufs_fill_super);
  682. }
  683. static struct file_system_type spufs_type = {
  684. .owner = THIS_MODULE,
  685. .name = "spufs",
  686. .mount = spufs_mount,
  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>");