Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cachefiles: enable on-demand read mode

Enable on-demand read mode by adding an optional parameter to the "bind"
command.

On-demand mode will be turned on when this parameter is "ondemand", i.e.
"bind ondemand". Otherwise cachefiles will work in the original mode.

Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
Link: https://lore.kernel.org/r/20220509074028.74954-7-jefflexu@linux.alibaba.com
Acked-by: David Howells <dhowells@redhat.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>

authored by

Jeffle Xu and committed by
Gao Xiang
4e4f1788 9032b6e8

+12 -5
+12 -5
fs/cachefiles/daemon.c
··· 755 755 cache->brun_percent >= 100) 756 756 return -ERANGE; 757 757 758 - if (*args) { 759 - pr_err("'bind' command doesn't take an argument\n"); 760 - return -EINVAL; 761 - } 762 - 763 758 if (!cache->rootdirname) { 764 759 pr_err("No cache directory specified\n"); 765 760 return -EINVAL; ··· 764 769 if (test_bit(CACHEFILES_READY, &cache->flags)) { 765 770 pr_err("Cache already bound\n"); 766 771 return -EBUSY; 772 + } 773 + 774 + if (IS_ENABLED(CONFIG_CACHEFILES_ONDEMAND)) { 775 + if (!strcmp(args, "ondemand")) { 776 + set_bit(CACHEFILES_ONDEMAND_MODE, &cache->flags); 777 + } else if (*args) { 778 + pr_err("Invalid argument to the 'bind' command\n"); 779 + return -EINVAL; 780 + } 781 + } else if (*args) { 782 + pr_err("'bind' command doesn't take an argument\n"); 783 + return -EINVAL; 767 784 } 768 785 769 786 /* Make sure we have copies of the tag string */