fscache.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2022, Alibaba Cloud
  4. * Copyright (C) 2022, Bytedance Inc. All rights reserved.
  5. */
  6. #include <linux/fscache.h>
  7. #include "internal.h"
  8. static DEFINE_MUTEX(erofs_domain_list_lock);
  9. static DEFINE_MUTEX(erofs_domain_cookies_lock);
  10. static LIST_HEAD(erofs_domain_list);
  11. static LIST_HEAD(erofs_domain_cookies_list);
  12. static struct vfsmount *erofs_pseudo_mnt;
  13. struct erofs_fscache_io {
  14. struct netfs_cache_resources cres;
  15. struct iov_iter iter;
  16. netfs_io_terminated_t end_io;
  17. void *private;
  18. refcount_t ref;
  19. };
  20. struct erofs_fscache_rq {
  21. struct address_space *mapping; /* The mapping being accessed */
  22. loff_t start; /* Start position */
  23. size_t len; /* Length of the request */
  24. size_t submitted; /* Length of submitted */
  25. short error; /* 0 or error that occurred */
  26. refcount_t ref;
  27. };
  28. static bool erofs_fscache_io_put(struct erofs_fscache_io *io)
  29. {
  30. if (!refcount_dec_and_test(&io->ref))
  31. return false;
  32. if (io->cres.ops)
  33. io->cres.ops->end_operation(&io->cres);
  34. kfree(io);
  35. return true;
  36. }
  37. static void erofs_fscache_req_complete(struct erofs_fscache_rq *req)
  38. {
  39. struct folio *folio;
  40. bool failed = req->error;
  41. pgoff_t start_page = req->start / PAGE_SIZE;
  42. pgoff_t last_page = ((req->start + req->len) / PAGE_SIZE) - 1;
  43. XA_STATE(xas, &req->mapping->i_pages, start_page);
  44. rcu_read_lock();
  45. xas_for_each(&xas, folio, last_page) {
  46. if (xas_retry(&xas, folio))
  47. continue;
  48. if (!failed)
  49. folio_mark_uptodate(folio);
  50. folio_unlock(folio);
  51. }
  52. rcu_read_unlock();
  53. }
  54. static void erofs_fscache_req_put(struct erofs_fscache_rq *req)
  55. {
  56. if (!refcount_dec_and_test(&req->ref))
  57. return;
  58. erofs_fscache_req_complete(req);
  59. kfree(req);
  60. }
  61. static struct erofs_fscache_rq *erofs_fscache_req_alloc(struct address_space *mapping,
  62. loff_t start, size_t len)
  63. {
  64. struct erofs_fscache_rq *req = kzalloc_obj(*req);
  65. if (!req)
  66. return NULL;
  67. req->mapping = mapping;
  68. req->start = start;
  69. req->len = len;
  70. refcount_set(&req->ref, 1);
  71. return req;
  72. }
  73. static void erofs_fscache_req_io_put(struct erofs_fscache_io *io)
  74. {
  75. struct erofs_fscache_rq *req = io->private;
  76. if (erofs_fscache_io_put(io))
  77. erofs_fscache_req_put(req);
  78. }
  79. static void erofs_fscache_req_end_io(void *priv, ssize_t transferred_or_error)
  80. {
  81. struct erofs_fscache_io *io = priv;
  82. struct erofs_fscache_rq *req = io->private;
  83. if (IS_ERR_VALUE(transferred_or_error))
  84. req->error = transferred_or_error;
  85. erofs_fscache_req_io_put(io);
  86. }
  87. static struct erofs_fscache_io *erofs_fscache_req_io_alloc(struct erofs_fscache_rq *req)
  88. {
  89. struct erofs_fscache_io *io = kzalloc_obj(*io);
  90. if (!io)
  91. return NULL;
  92. io->end_io = erofs_fscache_req_end_io;
  93. io->private = req;
  94. refcount_inc(&req->ref);
  95. refcount_set(&io->ref, 1);
  96. return io;
  97. }
  98. /*
  99. * Read data from fscache described by cookie at pstart physical address
  100. * offset, and fill the read data into buffer described by io->iter.
  101. */
  102. static int erofs_fscache_read_io_async(struct fscache_cookie *cookie,
  103. loff_t pstart, struct erofs_fscache_io *io)
  104. {
  105. enum netfs_io_source source;
  106. struct netfs_cache_resources *cres = &io->cres;
  107. struct iov_iter *iter = &io->iter;
  108. int ret;
  109. ret = fscache_begin_read_operation(cres, cookie);
  110. if (ret)
  111. return ret;
  112. while (iov_iter_count(iter)) {
  113. size_t orig_count = iov_iter_count(iter), len = orig_count;
  114. unsigned long flags = 1 << NETFS_SREQ_ONDEMAND;
  115. source = cres->ops->prepare_ondemand_read(cres,
  116. pstart, &len, LLONG_MAX, &flags, 0);
  117. if (WARN_ON(len == 0))
  118. source = NETFS_INVALID_READ;
  119. if (source != NETFS_READ_FROM_CACHE) {
  120. erofs_err(NULL, "prepare_ondemand_read failed (source %d)", source);
  121. return -EIO;
  122. }
  123. iov_iter_truncate(iter, len);
  124. refcount_inc(&io->ref);
  125. ret = fscache_read(cres, pstart, iter, NETFS_READ_HOLE_FAIL,
  126. io->end_io, io);
  127. if (ret == -EIOCBQUEUED)
  128. ret = 0;
  129. if (ret) {
  130. erofs_err(NULL, "fscache_read failed (ret %d)", ret);
  131. return ret;
  132. }
  133. if (WARN_ON(iov_iter_count(iter)))
  134. return -EIO;
  135. iov_iter_reexpand(iter, orig_count - len);
  136. pstart += len;
  137. }
  138. return 0;
  139. }
  140. struct erofs_fscache_bio {
  141. struct erofs_fscache_io io;
  142. struct bio bio; /* w/o bdev to share bio_add_page/endio() */
  143. struct bio_vec bvecs[BIO_MAX_VECS];
  144. };
  145. static void erofs_fscache_bio_endio(void *priv, ssize_t transferred_or_error)
  146. {
  147. struct erofs_fscache_bio *io = priv;
  148. if (IS_ERR_VALUE(transferred_or_error))
  149. io->bio.bi_status = errno_to_blk_status(transferred_or_error);
  150. bio_endio(&io->bio);
  151. BUILD_BUG_ON(offsetof(struct erofs_fscache_bio, io) != 0);
  152. erofs_fscache_io_put(&io->io);
  153. }
  154. struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev)
  155. {
  156. struct erofs_fscache_bio *io;
  157. io = kmalloc_obj(*io, GFP_KERNEL | __GFP_NOFAIL);
  158. bio_init(&io->bio, NULL, io->bvecs, BIO_MAX_VECS, REQ_OP_READ);
  159. io->io.private = mdev->m_dif->fscache->cookie;
  160. io->io.end_io = erofs_fscache_bio_endio;
  161. refcount_set(&io->io.ref, 1);
  162. return &io->bio;
  163. }
  164. void erofs_fscache_submit_bio(struct bio *bio)
  165. {
  166. struct erofs_fscache_bio *io = container_of(bio,
  167. struct erofs_fscache_bio, bio);
  168. int ret;
  169. iov_iter_bvec(&io->io.iter, ITER_DEST, io->bvecs, bio->bi_vcnt,
  170. bio->bi_iter.bi_size);
  171. ret = erofs_fscache_read_io_async(io->io.private,
  172. bio->bi_iter.bi_sector << 9, &io->io);
  173. erofs_fscache_io_put(&io->io);
  174. if (!ret)
  175. return;
  176. bio->bi_status = errno_to_blk_status(ret);
  177. bio_endio(bio);
  178. }
  179. static int erofs_fscache_meta_read_folio(struct file *data, struct folio *folio)
  180. {
  181. struct erofs_fscache *ctx = folio->mapping->host->i_private;
  182. int ret = -ENOMEM;
  183. struct erofs_fscache_rq *req;
  184. struct erofs_fscache_io *io;
  185. req = erofs_fscache_req_alloc(folio->mapping,
  186. folio_pos(folio), folio_size(folio));
  187. if (!req) {
  188. folio_unlock(folio);
  189. return ret;
  190. }
  191. io = erofs_fscache_req_io_alloc(req);
  192. if (!io) {
  193. req->error = ret;
  194. goto out;
  195. }
  196. iov_iter_xarray(&io->iter, ITER_DEST, &folio->mapping->i_pages,
  197. folio_pos(folio), folio_size(folio));
  198. ret = erofs_fscache_read_io_async(ctx->cookie, folio_pos(folio), io);
  199. if (ret)
  200. req->error = ret;
  201. erofs_fscache_req_io_put(io);
  202. out:
  203. erofs_fscache_req_put(req);
  204. return ret;
  205. }
  206. static int erofs_fscache_data_read_slice(struct erofs_fscache_rq *req)
  207. {
  208. struct address_space *mapping = req->mapping;
  209. struct inode *inode = mapping->host;
  210. struct super_block *sb = inode->i_sb;
  211. struct erofs_fscache_io *io;
  212. struct erofs_map_blocks map;
  213. struct erofs_map_dev mdev;
  214. loff_t pos = req->start + req->submitted;
  215. size_t count;
  216. int ret;
  217. map.m_la = pos;
  218. ret = erofs_map_blocks(inode, &map);
  219. if (ret)
  220. return ret;
  221. if (map.m_flags & EROFS_MAP_META) {
  222. struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
  223. struct iov_iter iter;
  224. size_t size = map.m_llen;
  225. void *src;
  226. src = erofs_read_metabuf(&buf, sb, map.m_pa,
  227. erofs_inode_in_metabox(inode));
  228. if (IS_ERR(src))
  229. return PTR_ERR(src);
  230. iov_iter_xarray(&iter, ITER_DEST, &mapping->i_pages, pos, PAGE_SIZE);
  231. if (copy_to_iter(src, size, &iter) != size) {
  232. erofs_put_metabuf(&buf);
  233. return -EFAULT;
  234. }
  235. iov_iter_zero(PAGE_SIZE - size, &iter);
  236. erofs_put_metabuf(&buf);
  237. req->submitted += PAGE_SIZE;
  238. return 0;
  239. }
  240. count = req->len - req->submitted;
  241. if (!(map.m_flags & EROFS_MAP_MAPPED)) {
  242. struct iov_iter iter;
  243. iov_iter_xarray(&iter, ITER_DEST, &mapping->i_pages, pos, count);
  244. iov_iter_zero(count, &iter);
  245. req->submitted += count;
  246. return 0;
  247. }
  248. count = min_t(size_t, map.m_llen - (pos - map.m_la), count);
  249. DBG_BUGON(!count || count % PAGE_SIZE);
  250. mdev = (struct erofs_map_dev) {
  251. .m_deviceid = map.m_deviceid,
  252. .m_pa = map.m_pa,
  253. };
  254. ret = erofs_map_dev(sb, &mdev);
  255. if (ret)
  256. return ret;
  257. io = erofs_fscache_req_io_alloc(req);
  258. if (!io)
  259. return -ENOMEM;
  260. iov_iter_xarray(&io->iter, ITER_DEST, &mapping->i_pages, pos, count);
  261. ret = erofs_fscache_read_io_async(mdev.m_dif->fscache->cookie,
  262. mdev.m_pa + (pos - map.m_la), io);
  263. erofs_fscache_req_io_put(io);
  264. req->submitted += count;
  265. return ret;
  266. }
  267. static int erofs_fscache_data_read(struct erofs_fscache_rq *req)
  268. {
  269. int ret;
  270. do {
  271. ret = erofs_fscache_data_read_slice(req);
  272. if (ret)
  273. req->error = ret;
  274. } while (!ret && req->submitted < req->len);
  275. return ret;
  276. }
  277. static int erofs_fscache_read_folio(struct file *file, struct folio *folio)
  278. {
  279. struct erofs_fscache_rq *req;
  280. int ret;
  281. req = erofs_fscache_req_alloc(folio->mapping,
  282. folio_pos(folio), folio_size(folio));
  283. if (!req) {
  284. folio_unlock(folio);
  285. return -ENOMEM;
  286. }
  287. ret = erofs_fscache_data_read(req);
  288. erofs_fscache_req_put(req);
  289. return ret;
  290. }
  291. static void erofs_fscache_readahead(struct readahead_control *rac)
  292. {
  293. struct erofs_fscache_rq *req;
  294. if (!readahead_count(rac))
  295. return;
  296. req = erofs_fscache_req_alloc(rac->mapping,
  297. readahead_pos(rac), readahead_length(rac));
  298. if (!req)
  299. return;
  300. /* The request completion will drop refs on the folios. */
  301. while (readahead_folio(rac))
  302. ;
  303. erofs_fscache_data_read(req);
  304. erofs_fscache_req_put(req);
  305. }
  306. static const struct address_space_operations erofs_fscache_meta_aops = {
  307. .read_folio = erofs_fscache_meta_read_folio,
  308. };
  309. const struct address_space_operations erofs_fscache_access_aops = {
  310. .read_folio = erofs_fscache_read_folio,
  311. .readahead = erofs_fscache_readahead,
  312. };
  313. static void erofs_fscache_domain_put(struct erofs_domain *domain)
  314. {
  315. mutex_lock(&erofs_domain_list_lock);
  316. if (refcount_dec_and_test(&domain->ref)) {
  317. list_del(&domain->list);
  318. if (list_empty(&erofs_domain_list)) {
  319. kern_unmount(erofs_pseudo_mnt);
  320. erofs_pseudo_mnt = NULL;
  321. }
  322. fscache_relinquish_volume(domain->volume, NULL, false);
  323. mutex_unlock(&erofs_domain_list_lock);
  324. kfree_sensitive(domain->domain_id);
  325. kfree(domain);
  326. return;
  327. }
  328. mutex_unlock(&erofs_domain_list_lock);
  329. }
  330. static int erofs_fscache_register_volume(struct super_block *sb)
  331. {
  332. struct erofs_sb_info *sbi = EROFS_SB(sb);
  333. char *domain_id = sbi->domain_id;
  334. struct fscache_volume *volume;
  335. char *name;
  336. int ret = 0;
  337. name = kasprintf(GFP_KERNEL, "erofs,%s",
  338. domain_id ? domain_id : sbi->fsid);
  339. if (!name)
  340. return -ENOMEM;
  341. volume = fscache_acquire_volume(name, NULL, NULL, 0);
  342. if (IS_ERR_OR_NULL(volume)) {
  343. erofs_err(sb, "failed to register volume for %s", name);
  344. ret = volume ? PTR_ERR(volume) : -EOPNOTSUPP;
  345. volume = NULL;
  346. }
  347. sbi->volume = volume;
  348. kfree(name);
  349. return ret;
  350. }
  351. static int erofs_fscache_init_domain(struct super_block *sb)
  352. {
  353. int err;
  354. struct erofs_domain *domain;
  355. struct erofs_sb_info *sbi = EROFS_SB(sb);
  356. domain = kzalloc_obj(struct erofs_domain);
  357. if (!domain)
  358. return -ENOMEM;
  359. domain->domain_id = kstrdup(sbi->domain_id, GFP_KERNEL);
  360. if (!domain->domain_id) {
  361. kfree(domain);
  362. return -ENOMEM;
  363. }
  364. err = erofs_fscache_register_volume(sb);
  365. if (err)
  366. goto out;
  367. if (!erofs_pseudo_mnt) {
  368. struct vfsmount *mnt = kern_mount(&erofs_anon_fs_type);
  369. if (IS_ERR(mnt)) {
  370. err = PTR_ERR(mnt);
  371. goto out;
  372. }
  373. erofs_pseudo_mnt = mnt;
  374. }
  375. domain->volume = sbi->volume;
  376. refcount_set(&domain->ref, 1);
  377. list_add(&domain->list, &erofs_domain_list);
  378. sbi->domain = domain;
  379. return 0;
  380. out:
  381. kfree_sensitive(domain->domain_id);
  382. kfree(domain);
  383. return err;
  384. }
  385. static int erofs_fscache_register_domain(struct super_block *sb)
  386. {
  387. int err;
  388. struct erofs_domain *domain;
  389. struct erofs_sb_info *sbi = EROFS_SB(sb);
  390. mutex_lock(&erofs_domain_list_lock);
  391. list_for_each_entry(domain, &erofs_domain_list, list) {
  392. if (!strcmp(domain->domain_id, sbi->domain_id)) {
  393. sbi->domain = domain;
  394. sbi->volume = domain->volume;
  395. refcount_inc(&domain->ref);
  396. mutex_unlock(&erofs_domain_list_lock);
  397. return 0;
  398. }
  399. }
  400. err = erofs_fscache_init_domain(sb);
  401. mutex_unlock(&erofs_domain_list_lock);
  402. return err;
  403. }
  404. static struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb,
  405. char *name, unsigned int flags)
  406. {
  407. struct fscache_volume *volume = EROFS_SB(sb)->volume;
  408. struct erofs_fscache *ctx;
  409. struct fscache_cookie *cookie;
  410. struct super_block *isb;
  411. struct inode *inode;
  412. int ret;
  413. ctx = kzalloc_obj(*ctx);
  414. if (!ctx)
  415. return ERR_PTR(-ENOMEM);
  416. INIT_LIST_HEAD(&ctx->node);
  417. refcount_set(&ctx->ref, 1);
  418. cookie = fscache_acquire_cookie(volume, FSCACHE_ADV_WANT_CACHE_SIZE,
  419. name, strlen(name), NULL, 0, 0);
  420. if (!cookie) {
  421. erofs_err(sb, "failed to get cookie for %s", name);
  422. ret = -EINVAL;
  423. goto err;
  424. }
  425. fscache_use_cookie(cookie, false);
  426. /*
  427. * Allocate anonymous inode in global pseudo mount for shareable blobs,
  428. * so that they are accessible among erofs fs instances.
  429. */
  430. isb = flags & EROFS_REG_COOKIE_SHARE ? erofs_pseudo_mnt->mnt_sb : sb;
  431. inode = new_inode(isb);
  432. if (!inode) {
  433. erofs_err(sb, "failed to get anon inode for %s", name);
  434. ret = -ENOMEM;
  435. goto err_cookie;
  436. }
  437. inode->i_size = OFFSET_MAX;
  438. inode->i_mapping->a_ops = &erofs_fscache_meta_aops;
  439. mapping_set_gfp_mask(inode->i_mapping, GFP_KERNEL);
  440. inode->i_blkbits = EROFS_SB(sb)->blkszbits;
  441. inode->i_private = ctx;
  442. ctx->cookie = cookie;
  443. ctx->inode = inode;
  444. return ctx;
  445. err_cookie:
  446. fscache_unuse_cookie(cookie, NULL, NULL);
  447. fscache_relinquish_cookie(cookie, false);
  448. err:
  449. kfree(ctx);
  450. return ERR_PTR(ret);
  451. }
  452. static void erofs_fscache_relinquish_cookie(struct erofs_fscache *ctx)
  453. {
  454. fscache_unuse_cookie(ctx->cookie, NULL, NULL);
  455. fscache_relinquish_cookie(ctx->cookie, false);
  456. iput(ctx->inode);
  457. kfree(ctx->name);
  458. kfree(ctx);
  459. }
  460. static struct erofs_fscache *erofs_domain_init_cookie(struct super_block *sb,
  461. char *name, unsigned int flags)
  462. {
  463. struct erofs_fscache *ctx;
  464. struct erofs_domain *domain = EROFS_SB(sb)->domain;
  465. ctx = erofs_fscache_acquire_cookie(sb, name, flags);
  466. if (IS_ERR(ctx))
  467. return ctx;
  468. ctx->name = kstrdup(name, GFP_KERNEL);
  469. if (!ctx->name) {
  470. erofs_fscache_relinquish_cookie(ctx);
  471. return ERR_PTR(-ENOMEM);
  472. }
  473. refcount_inc(&domain->ref);
  474. ctx->domain = domain;
  475. list_add(&ctx->node, &erofs_domain_cookies_list);
  476. return ctx;
  477. }
  478. static struct erofs_fscache *erofs_domain_register_cookie(struct super_block *sb,
  479. char *name, unsigned int flags)
  480. {
  481. struct erofs_fscache *ctx;
  482. struct erofs_domain *domain = EROFS_SB(sb)->domain;
  483. flags |= EROFS_REG_COOKIE_SHARE;
  484. mutex_lock(&erofs_domain_cookies_lock);
  485. list_for_each_entry(ctx, &erofs_domain_cookies_list, node) {
  486. if (ctx->domain != domain || strcmp(ctx->name, name))
  487. continue;
  488. if (!(flags & EROFS_REG_COOKIE_NEED_NOEXIST)) {
  489. refcount_inc(&ctx->ref);
  490. } else {
  491. erofs_err(sb, "%s already exists in domain %s", name,
  492. domain->domain_id);
  493. ctx = ERR_PTR(-EEXIST);
  494. }
  495. mutex_unlock(&erofs_domain_cookies_lock);
  496. return ctx;
  497. }
  498. ctx = erofs_domain_init_cookie(sb, name, flags);
  499. mutex_unlock(&erofs_domain_cookies_lock);
  500. return ctx;
  501. }
  502. struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb,
  503. char *name,
  504. unsigned int flags)
  505. {
  506. if (EROFS_SB(sb)->domain_id)
  507. return erofs_domain_register_cookie(sb, name, flags);
  508. return erofs_fscache_acquire_cookie(sb, name, flags);
  509. }
  510. void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx)
  511. {
  512. struct erofs_domain *domain = NULL;
  513. if (!ctx)
  514. return;
  515. if (!ctx->domain)
  516. return erofs_fscache_relinquish_cookie(ctx);
  517. mutex_lock(&erofs_domain_cookies_lock);
  518. if (refcount_dec_and_test(&ctx->ref)) {
  519. domain = ctx->domain;
  520. list_del(&ctx->node);
  521. erofs_fscache_relinquish_cookie(ctx);
  522. }
  523. mutex_unlock(&erofs_domain_cookies_lock);
  524. if (domain)
  525. erofs_fscache_domain_put(domain);
  526. }
  527. int erofs_fscache_register_fs(struct super_block *sb)
  528. {
  529. int ret;
  530. struct erofs_sb_info *sbi = EROFS_SB(sb);
  531. struct erofs_fscache *fscache;
  532. unsigned int flags = 0;
  533. if (sbi->domain_id)
  534. ret = erofs_fscache_register_domain(sb);
  535. else
  536. ret = erofs_fscache_register_volume(sb);
  537. if (ret)
  538. return ret;
  539. /*
  540. * When shared domain is enabled, using NEED_NOEXIST to guarantee
  541. * the primary data blob (aka fsid) is unique in the shared domain.
  542. *
  543. * For non-shared-domain case, fscache_acquire_volume() invoked by
  544. * erofs_fscache_register_volume() has already guaranteed
  545. * the uniqueness of primary data blob.
  546. *
  547. * Acquired domain/volume will be relinquished in kill_sb() on error.
  548. */
  549. if (sbi->domain_id)
  550. flags |= EROFS_REG_COOKIE_NEED_NOEXIST;
  551. fscache = erofs_fscache_register_cookie(sb, sbi->fsid, flags);
  552. if (IS_ERR(fscache))
  553. return PTR_ERR(fscache);
  554. sbi->dif0.fscache = fscache;
  555. return 0;
  556. }
  557. void erofs_fscache_unregister_fs(struct super_block *sb)
  558. {
  559. struct erofs_sb_info *sbi = EROFS_SB(sb);
  560. erofs_fscache_unregister_cookie(sbi->dif0.fscache);
  561. if (sbi->domain)
  562. erofs_fscache_domain_put(sbi->domain);
  563. else
  564. fscache_relinquish_volume(sbi->volume, NULL, false);
  565. sbi->dif0.fscache = NULL;
  566. sbi->volume = NULL;
  567. sbi->domain = NULL;
  568. }