Skip to content

Commit a9fba24

Browse files
pjcuadratorvalds
authored andcommitted
coda: add hinting support for partial file caching
This adds support for partial file caching in Coda. Every read, write and mmap informs the userspace cache manager about what part of a file is about to be accessed so that the cache manager can ensure the relevant parts are available before the operation is allowed to proceed. When a read or write operation completes, this is also reported to allow the cache manager to track when partially cached content can be released. If the cache manager does not support partial file caching, or when the entire file has been fetched into the local cache, the cache manager may return an EOPNOTSUPP error to indicate that intent upcalls are no longer necessary until the file is closed. [akpm@linux-foundation.org: little whitespace fixup] Link: http://lkml.kernel.org/r/20190618181301.6960-1-jaharkes@cs.cmu.edu Signed-off-by: Pedro Cuadra <pjcuadra@gmail.com> Signed-off-by: Jan Harkes <jaharkes@cs.cmu.edu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 5bb4481 commit a9fba24

6 files changed

Lines changed: 139 additions & 27 deletions

File tree

‎fs/coda/coda_fs_i.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct coda_file_info {
4040
int cfi_magic; /* magic number */
4141
struct file *cfi_container; /* container file for this cnode */
4242
unsigned int cfi_mapcount; /* nr of times this file is mapped */
43+
bool cfi_access_intent; /* is access intent supported */
4344
};
4445

4546
/* flags */

‎fs/coda/coda_psdev.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ int coda_downcall(struct venus_comm *vcp, int opcode, union outputArgs *out,
8383
size_t nbytes);
8484
int venus_fsync(struct super_block *sb, struct CodaFid *fid);
8585
int venus_statfs(struct dentry *dentry, struct kstatfs *sfs);
86+
int venus_access_intent(struct super_block *sb, struct CodaFid *fid,
87+
bool *access_intent_supported,
88+
size_t count, loff_t ppos, int type);
8689

8790
/*
8891
* Statistics

‎fs/coda/file.c‎

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/string.h>
2121
#include <linux/slab.h>
2222
#include <linux/uaccess.h>
23+
#include <linux/uio.h>
2324

2425
#include <linux/coda.h>
2526
#include "coda_psdev.h"
@@ -37,9 +38,25 @@ static ssize_t
3738
coda_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
3839
{
3940
struct file *coda_file = iocb->ki_filp;
41+
struct inode *coda_inode = file_inode(coda_file);
4042
struct coda_file_info *cfi = coda_ftoc(coda_file);
43+
loff_t ki_pos = iocb->ki_pos;
44+
size_t count = iov_iter_count(to);
45+
ssize_t ret;
46+
47+
ret = venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
48+
&cfi->cfi_access_intent,
49+
count, ki_pos, CODA_ACCESS_TYPE_READ);
50+
if (ret)
51+
goto finish_read;
4152

42-
return vfs_iter_read(cfi->cfi_container, to, &iocb->ki_pos, 0);
53+
ret = vfs_iter_read(cfi->cfi_container, to, &iocb->ki_pos, 0);
54+
55+
finish_read:
56+
venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
57+
&cfi->cfi_access_intent,
58+
count, ki_pos, CODA_ACCESS_TYPE_READ_FINISH);
59+
return ret;
4360
}
4461

4562
static ssize_t
@@ -48,10 +65,17 @@ coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to)
4865
struct file *coda_file = iocb->ki_filp;
4966
struct inode *coda_inode = file_inode(coda_file);
5067
struct coda_file_info *cfi = coda_ftoc(coda_file);
51-
struct file *host_file;
68+
struct file *host_file = cfi->cfi_container;
69+
loff_t ki_pos = iocb->ki_pos;
70+
size_t count = iov_iter_count(to);
5271
ssize_t ret;
5372

54-
host_file = cfi->cfi_container;
73+
ret = venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
74+
&cfi->cfi_access_intent,
75+
count, ki_pos, CODA_ACCESS_TYPE_WRITE);
76+
if (ret)
77+
goto finish_write;
78+
5579
file_start_write(host_file);
5680
inode_lock(coda_inode);
5781
ret = vfs_iter_write(cfi->cfi_container, to, &iocb->ki_pos, 0);
@@ -60,6 +84,11 @@ coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to)
6084
coda_inode->i_mtime = coda_inode->i_ctime = current_time(coda_inode);
6185
inode_unlock(coda_inode);
6286
file_end_write(host_file);
87+
88+
finish_write:
89+
venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
90+
&cfi->cfi_access_intent,
91+
count, ki_pos, CODA_ACCESS_TYPE_WRITE_FINISH);
6392
return ret;
6493
}
6594

@@ -94,29 +123,35 @@ coda_vm_close(struct vm_area_struct *vma)
94123
static int
95124
coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
96125
{
97-
struct coda_file_info *cfi;
126+
struct inode *coda_inode = file_inode(coda_file);
127+
struct coda_file_info *cfi = coda_ftoc(coda_file);
128+
struct file *host_file = cfi->cfi_container;
129+
struct inode *host_inode = file_inode(host_file);
98130
struct coda_inode_info *cii;
99-
struct file *host_file;
100-
struct inode *coda_inode, *host_inode;
101131
struct coda_vm_ops *cvm_ops;
132+
loff_t ppos;
133+
size_t count;
102134
int ret;
103135

104-
cfi = coda_ftoc(coda_file);
105-
host_file = cfi->cfi_container;
106-
107136
if (!host_file->f_op->mmap)
108137
return -ENODEV;
109138

110139
if (WARN_ON(coda_file != vma->vm_file))
111140
return -EIO;
112141

142+
count = vma->vm_end - vma->vm_start;
143+
ppos = vma->vm_pgoff * PAGE_SIZE;
144+
145+
ret = venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
146+
&cfi->cfi_access_intent,
147+
count, ppos, CODA_ACCESS_TYPE_MMAP);
148+
if (ret)
149+
return ret;
150+
113151
cvm_ops = kmalloc(sizeof(struct coda_vm_ops), GFP_KERNEL);
114152
if (!cvm_ops)
115153
return -ENOMEM;
116154

117-
coda_inode = file_inode(coda_file);
118-
host_inode = file_inode(host_file);
119-
120155
cii = ITOC(coda_inode);
121156
spin_lock(&cii->c_lock);
122157
coda_file->f_mapping = host_file->f_mapping;
@@ -188,6 +223,8 @@ int coda_open(struct inode *coda_inode, struct file *coda_file)
188223
cfi->cfi_magic = CODA_MAGIC;
189224
cfi->cfi_mapcount = 0;
190225
cfi->cfi_container = host_file;
226+
/* assume access intents are supported unless we hear otherwise */
227+
cfi->cfi_access_intent = true;
191228

192229
BUG_ON(coda_file->private_data != NULL);
193230
coda_file->private_data = cfi;

‎fs/coda/psdev.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ MODULE_AUTHOR("Jan Harkes, Peter J. Braam");
388388
MODULE_DESCRIPTION("Coda Distributed File System VFS interface");
389389
MODULE_ALIAS_CHARDEV_MAJOR(CODA_PSDEV_MAJOR);
390390
MODULE_LICENSE("GPL");
391-
MODULE_VERSION("6.11");
391+
MODULE_VERSION("7.0");
392392

393393
static int __init init_coda(void)
394394
{

‎fs/coda/upcall.c‎

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,47 @@ int venus_statfs(struct dentry *dentry, struct kstatfs *sfs)
569569
return error;
570570
}
571571

572+
int venus_access_intent(struct super_block *sb, struct CodaFid *fid,
573+
bool *access_intent_supported,
574+
size_t count, loff_t ppos, int type)
575+
{
576+
union inputArgs *inp;
577+
union outputArgs *outp;
578+
int insize, outsize, error;
579+
bool finalizer =
580+
type == CODA_ACCESS_TYPE_READ_FINISH ||
581+
type == CODA_ACCESS_TYPE_WRITE_FINISH;
582+
583+
if (!*access_intent_supported && !finalizer)
584+
return 0;
585+
586+
insize = SIZE(access_intent);
587+
UPARG(CODA_ACCESS_INTENT);
588+
589+
inp->coda_access_intent.VFid = *fid;
590+
inp->coda_access_intent.count = count;
591+
inp->coda_access_intent.pos = ppos;
592+
inp->coda_access_intent.type = type;
593+
594+
error = coda_upcall(coda_vcp(sb), insize,
595+
finalizer ? NULL : &outsize, inp);
596+
597+
/*
598+
* we have to free the request buffer for synchronous upcalls
599+
* or when asynchronous upcalls fail, but not when asynchronous
600+
* upcalls succeed
601+
*/
602+
if (!finalizer || error)
603+
kvfree(inp);
604+
605+
/* Chunked access is not supported or an old Coda client */
606+
if (error == -EOPNOTSUPP) {
607+
*access_intent_supported = false;
608+
error = 0;
609+
}
610+
return error;
611+
}
612+
572613
/*
573614
* coda_upcall and coda_downcall routines.
574615
*/
@@ -598,10 +639,12 @@ static void coda_unblock_signals(sigset_t *old)
598639
* has seen them,
599640
* - CODA_CLOSE or CODA_RELEASE upcall (to avoid reference count problems)
600641
* - CODA_STORE (to avoid data loss)
642+
* - CODA_ACCESS_INTENT (to avoid reference count problems)
601643
*/
602644
#define CODA_INTERRUPTIBLE(r) (!coda_hard && \
603645
(((r)->uc_opcode != CODA_CLOSE && \
604646
(r)->uc_opcode != CODA_STORE && \
647+
(r)->uc_opcode != CODA_ACCESS_INTENT && \
605648
(r)->uc_opcode != CODA_RELEASE) || \
606649
(r)->uc_flags & CODA_REQ_READ))
607650

@@ -687,21 +730,25 @@ static int coda_upcall(struct venus_comm *vcp,
687730
goto exit;
688731
}
689732

733+
buffer->ih.unique = ++vcp->vc_seq;
734+
690735
req->uc_data = (void *)buffer;
691-
req->uc_flags = 0;
736+
req->uc_flags = outSize ? 0 : CODA_REQ_ASYNC;
692737
req->uc_inSize = inSize;
693-
req->uc_outSize = *outSize ? *outSize : inSize;
694-
req->uc_opcode = ((union inputArgs *)buffer)->ih.opcode;
695-
req->uc_unique = ++vcp->vc_seq;
738+
req->uc_outSize = (outSize && *outSize) ? *outSize : inSize;
739+
req->uc_opcode = buffer->ih.opcode;
740+
req->uc_unique = buffer->ih.unique;
696741
init_waitqueue_head(&req->uc_sleep);
697742

698-
/* Fill in the common input args. */
699-
((union inputArgs *)buffer)->ih.unique = req->uc_unique;
700-
701743
/* Append msg to pending queue and poke Venus. */
702744
list_add_tail(&req->uc_chain, &vcp->vc_pending);
703-
704745
wake_up_interruptible(&vcp->vc_waitq);
746+
747+
if (req->uc_flags & CODA_REQ_ASYNC) {
748+
mutex_unlock(&vcp->vc_mutex);
749+
return 0;
750+
}
751+
705752
/* We can be interrupted while we wait for Venus to process
706753
* our request. If the interrupt occurs before Venus has read
707754
* the request, we dequeue and return. If it occurs after the
@@ -743,20 +790,20 @@ static int coda_upcall(struct venus_comm *vcp,
743790
sig_req = kmalloc(sizeof(struct upc_req), GFP_KERNEL);
744791
if (!sig_req) goto exit;
745792

746-
sig_req->uc_data = kvzalloc(sizeof(struct coda_in_hdr), GFP_KERNEL);
747-
if (!sig_req->uc_data) {
793+
sig_inputArgs = kvzalloc(sizeof(struct coda_in_hdr), GFP_KERNEL);
794+
if (!sig_inputArgs) {
748795
kfree(sig_req);
749796
goto exit;
750797
}
751798

752799
error = -EINTR;
753-
sig_inputArgs = (union inputArgs *)sig_req->uc_data;
754800
sig_inputArgs->ih.opcode = CODA_SIGNAL;
755801
sig_inputArgs->ih.unique = req->uc_unique;
756802

757803
sig_req->uc_flags = CODA_REQ_ASYNC;
758804
sig_req->uc_opcode = sig_inputArgs->ih.opcode;
759805
sig_req->uc_unique = sig_inputArgs->ih.unique;
806+
sig_req->uc_data = (void *)sig_inputArgs;
760807
sig_req->uc_inSize = sizeof(struct coda_in_hdr);
761808
sig_req->uc_outSize = sizeof(struct coda_in_hdr);
762809

@@ -911,4 +958,3 @@ int coda_downcall(struct venus_comm *vcp, int opcode, union outputArgs *out,
911958
iput(inode);
912959
return 0;
913960
}
914-

‎include/uapi/linux/coda.h‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ struct coda_statfs {
271271
#define CODA_STATFS 34
272272
#define CODA_STORE 35
273273
#define CODA_RELEASE 36
274-
#define CODA_NCALLS 37
274+
#define CODA_ACCESS_INTENT 37
275+
#define CODA_NCALLS 38
275276

276277
#define DOWNCALL(opcode) (opcode >= CODA_REPLACE && opcode <= CODA_PURGEFID)
277278

@@ -281,8 +282,12 @@ struct coda_statfs {
281282

282283
#define CIOC_KERNEL_VERSION _IOWR('c', 10, size_t)
283284

285+
// CODA_KERNEL_VERSION 0 /* don't care about kernel version number */
286+
// CODA_KERNEL_VERSION 1 /* The old venus 4.6 compatible interface */
287+
// CODA_KERNEL_VERSION 2 /* venus_lookup gets an extra parameter */
284288
// CODA_KERNEL_VERSION 3 /* 128-bit file identifiers */
285-
#define CODA_KERNEL_VERSION 4 /* 64-bit timespec */
289+
// CODA_KERNEL_VERSION 4 /* 64-bit timespec */
290+
#define CODA_KERNEL_VERSION 5 /* access intent support */
286291

287292
/*
288293
* Venus <-> Coda RPC arguments
@@ -637,6 +642,25 @@ struct coda_statfs_out {
637642
struct coda_statfs stat;
638643
};
639644

645+
#define CODA_ACCESS_TYPE_READ 1
646+
#define CODA_ACCESS_TYPE_WRITE 2
647+
#define CODA_ACCESS_TYPE_MMAP 3
648+
#define CODA_ACCESS_TYPE_READ_FINISH 4
649+
#define CODA_ACCESS_TYPE_WRITE_FINISH 5
650+
651+
/* coda_access_intent: NO_OUT */
652+
struct coda_access_intent_in {
653+
struct coda_in_hdr ih;
654+
struct CodaFid VFid;
655+
int count;
656+
int pos;
657+
int type;
658+
};
659+
660+
struct coda_access_intent_out {
661+
struct coda_out_hdr out;
662+
};
663+
640664
/*
641665
* Occasionally, we don't cache the fid returned by CODA_LOOKUP.
642666
* For instance, if the fid is inconsistent.
@@ -668,6 +692,7 @@ union inputArgs {
668692
struct coda_open_by_fd_in coda_open_by_fd;
669693
struct coda_open_by_path_in coda_open_by_path;
670694
struct coda_statfs_in coda_statfs;
695+
struct coda_access_intent_in coda_access_intent;
671696
};
672697

673698
union outputArgs {

0 commit comments

Comments
 (0)