fscache.c (e6d9f9ba111b56154f1b1120252aff269cebd49c) fscache.c (39bfcb8138f6dc3375f23b1e62ccfc7c0d83295d)
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

--- 392 unchanged lines hidden (view full) ---

401 return;
402 }
403 mutex_unlock(&erofs_domain_list_lock);
404}
405
406static int erofs_fscache_register_volume(struct super_block *sb)
407{
408 struct erofs_sb_info *sbi = EROFS_SB(sb);
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

--- 392 unchanged lines hidden (view full) ---

401 return;
402 }
403 mutex_unlock(&erofs_domain_list_lock);
404}
405
406static int erofs_fscache_register_volume(struct super_block *sb)
407{
408 struct erofs_sb_info *sbi = EROFS_SB(sb);
409 char *domain_id = sbi->opt.domain_id;
409 char *domain_id = sbi->domain_id;
410 struct fscache_volume *volume;
411 char *name;
412 int ret = 0;
413
414 name = kasprintf(GFP_KERNEL, "erofs,%s",
410 struct fscache_volume *volume;
411 char *name;
412 int ret = 0;
413
414 name = kasprintf(GFP_KERNEL, "erofs,%s",
415 domain_id ? domain_id : sbi->opt.fsid);
415 domain_id ? domain_id : sbi->fsid);
416 if (!name)
417 return -ENOMEM;
418
419 volume = fscache_acquire_volume(name, NULL, NULL, 0);
420 if (IS_ERR_OR_NULL(volume)) {
421 erofs_err(sb, "failed to register volume for %s", name);
422 ret = volume ? PTR_ERR(volume) : -EOPNOTSUPP;
423 volume = NULL;

--- 9 unchanged lines hidden (view full) ---

433 int err;
434 struct erofs_domain *domain;
435 struct erofs_sb_info *sbi = EROFS_SB(sb);
436
437 domain = kzalloc(sizeof(struct erofs_domain), GFP_KERNEL);
438 if (!domain)
439 return -ENOMEM;
440
416 if (!name)
417 return -ENOMEM;
418
419 volume = fscache_acquire_volume(name, NULL, NULL, 0);
420 if (IS_ERR_OR_NULL(volume)) {
421 erofs_err(sb, "failed to register volume for %s", name);
422 ret = volume ? PTR_ERR(volume) : -EOPNOTSUPP;
423 volume = NULL;

--- 9 unchanged lines hidden (view full) ---

433 int err;
434 struct erofs_domain *domain;
435 struct erofs_sb_info *sbi = EROFS_SB(sb);
436
437 domain = kzalloc(sizeof(struct erofs_domain), GFP_KERNEL);
438 if (!domain)
439 return -ENOMEM;
440
441 domain->domain_id = kstrdup(sbi->opt.domain_id, GFP_KERNEL);
441 domain->domain_id = kstrdup(sbi->domain_id, GFP_KERNEL);
442 if (!domain->domain_id) {
443 kfree(domain);
444 return -ENOMEM;
445 }
446
447 err = erofs_fscache_register_volume(sb);
448 if (err)
449 goto out;

--- 20 unchanged lines hidden (view full) ---

470static int erofs_fscache_register_domain(struct super_block *sb)
471{
472 int err;
473 struct erofs_domain *domain;
474 struct erofs_sb_info *sbi = EROFS_SB(sb);
475
476 mutex_lock(&erofs_domain_list_lock);
477 list_for_each_entry(domain, &erofs_domain_list, list) {
442 if (!domain->domain_id) {
443 kfree(domain);
444 return -ENOMEM;
445 }
446
447 err = erofs_fscache_register_volume(sb);
448 if (err)
449 goto out;

--- 20 unchanged lines hidden (view full) ---

470static int erofs_fscache_register_domain(struct super_block *sb)
471{
472 int err;
473 struct erofs_domain *domain;
474 struct erofs_sb_info *sbi = EROFS_SB(sb);
475
476 mutex_lock(&erofs_domain_list_lock);
477 list_for_each_entry(domain, &erofs_domain_list, list) {
478 if (!strcmp(domain->domain_id, sbi->opt.domain_id)) {
478 if (!strcmp(domain->domain_id, sbi->domain_id)) {
479 sbi->domain = domain;
480 sbi->volume = domain->volume;
481 refcount_inc(&domain->ref);
482 mutex_unlock(&erofs_domain_list_lock);
483 return 0;
484 }
485 }
486 err = erofs_fscache_init_domain(sb);

--- 120 unchanged lines hidden (view full) ---

607 ctx = erofs_fscache_domain_init_cookie(sb, name, need_inode);
608 mutex_unlock(&erofs_domain_cookies_lock);
609 return ctx;
610}
611
612struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb,
613 char *name, bool need_inode)
614{
479 sbi->domain = domain;
480 sbi->volume = domain->volume;
481 refcount_inc(&domain->ref);
482 mutex_unlock(&erofs_domain_list_lock);
483 return 0;
484 }
485 }
486 err = erofs_fscache_init_domain(sb);

--- 120 unchanged lines hidden (view full) ---

607 ctx = erofs_fscache_domain_init_cookie(sb, name, need_inode);
608 mutex_unlock(&erofs_domain_cookies_lock);
609 return ctx;
610}
611
612struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb,
613 char *name, bool need_inode)
614{
615 if (EROFS_SB(sb)->opt.domain_id)
615 if (EROFS_SB(sb)->domain_id)
616 return erofs_domain_register_cookie(sb, name, need_inode);
617 return erofs_fscache_acquire_cookie(sb, name, need_inode);
618}
619
620void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx)
621{
622 bool drop;
623 struct erofs_domain *domain;

--- 15 unchanged lines hidden (view full) ---

639}
640
641int erofs_fscache_register_fs(struct super_block *sb)
642{
643 int ret;
644 struct erofs_sb_info *sbi = EROFS_SB(sb);
645 struct erofs_fscache *fscache;
646
616 return erofs_domain_register_cookie(sb, name, need_inode);
617 return erofs_fscache_acquire_cookie(sb, name, need_inode);
618}
619
620void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx)
621{
622 bool drop;
623 struct erofs_domain *domain;

--- 15 unchanged lines hidden (view full) ---

639}
640
641int erofs_fscache_register_fs(struct super_block *sb)
642{
643 int ret;
644 struct erofs_sb_info *sbi = EROFS_SB(sb);
645 struct erofs_fscache *fscache;
646
647 if (sbi->opt.domain_id)
647 if (sbi->domain_id)
648 ret = erofs_fscache_register_domain(sb);
649 else
650 ret = erofs_fscache_register_volume(sb);
651 if (ret)
652 return ret;
653
654 /* acquired domain/volume will be relinquished in kill_sb() on error */
648 ret = erofs_fscache_register_domain(sb);
649 else
650 ret = erofs_fscache_register_volume(sb);
651 if (ret)
652 return ret;
653
654 /* acquired domain/volume will be relinquished in kill_sb() on error */
655 fscache = erofs_fscache_register_cookie(sb, sbi->opt.fsid, true);
655 fscache = erofs_fscache_register_cookie(sb, sbi->fsid, true);
656 if (IS_ERR(fscache))
657 return PTR_ERR(fscache);
658
659 sbi->s_fscache = fscache;
660 return 0;
661}
662
663void erofs_fscache_unregister_fs(struct super_block *sb)

--- 14 unchanged lines hidden ---
656 if (IS_ERR(fscache))
657 return PTR_ERR(fscache);
658
659 sbi->s_fscache = fscache;
660 return 0;
661}
662
663void erofs_fscache_unregister_fs(struct super_block *sb)

--- 14 unchanged lines hidden ---