Skip to content

Commit

Permalink
Disable access intents after first EOPNOTSUPP response
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcuadra committed Oct 30, 2018
1 parent 6a6169c commit 60477fe
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 24 deletions.
1 change: 1 addition & 0 deletions linux4.x/coda_fs_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct coda_file_info {
int cfi_magic; /* magic number */
struct file *cfi_container; /* container file for this cnode */
unsigned int cfi_mapcount; /* nr of times this file is mapped */
bool cfi_access_intent; /* per-file access intent support */
};

#define CODA_FTOC(file) ((struct coda_file_info *)((file)->private_data))
Expand Down
113 changes: 89 additions & 24 deletions linux4.x/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,27 @@ coda_file_read(struct file *coda_file, char __user *buf, size_t count, loff_t *p

if (!host_file->f_op->read)
return -EINVAL;

err = venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode), count, *ppos, CODA_ACCESS_TYPE_READ);
if (err) goto finish_read;

if (cfi->cfi_access_intent) {
err = venus_access_intent(coda_inode->i_sb,
coda_i2f(coda_inode), count, *ppos,
CODA_ACCESS_TYPE_READ);
/* If not a VASTRO file, or old client version */
if (err == -EOPNOTSUPP) {
cfi->cfi_access_intent = false;
err = 0;
}
if (err) goto finish_read;
}

err = host_file->f_op->read(host_file, buf, count, ppos);

finish_read:
venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode), count, *ppos, CODA_ACCESS_TYPE_READ_FINISH);
if (cfi->cfi_access_intent) {
venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
count, *ppos,
CODA_ACCESS_TYPE_READ_FINISH);
}
return err;
}
static ssize_t
Expand All @@ -74,9 +87,18 @@ coda_file_write(struct file *coda_file, const char __user *buf, size_t count, lo

host_inode = file_inode(host_file);
file_start_write(host_file);

err = venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode), count, *ppos, CODA_ACCESS_TYPE_WRITE);
if (err) goto finish_write;

if (cfi->cfi_access_intent) {
err = venus_access_intent(coda_inode->i_sb,
coda_i2f(coda_inode), count, *ppos,
CODA_ACCESS_TYPE_WRITE);
/* If not a VASTRO file, or old client version */
if (err == -EOPNOTSUPP) {
cfi->cfi_access_intent = false;
err = 0;
}
if (err) goto finish_write;
}

mutex_lock(&coda_inode->i_mutex);

Expand All @@ -88,7 +110,11 @@ coda_file_write(struct file *coda_file, const char __user *buf, size_t count, lo
file_end_write(host_file);

finish_write:
venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode), count, *ppos, CODA_ACCESS_TYPE_WRITE_FINISH);
if (cfi->cfi_access_intent) {
venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
count, *ppos,
CODA_ACCESS_TYPE_WRITE_FINISH);
}
return ret;
}
#else
Expand All @@ -107,14 +133,30 @@ coda_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
ki_pos_tmp = iocb->ki_pos;
to_tmp = iov_iter_count(to);

err = venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode), iov_iter_count(to), iocb->ki_pos, CODA_ACCESS_TYPE_READ);
if (err) goto finish_read;

err = vfs_iter_read(cfi->cfi_container, to, &iocb->ki_pos, RWF_SYNC);
if (cfi->cfi_access_intent) {
err = venus_access_intent(coda_inode->i_sb,
coda_i2f(coda_inode),
iov_iter_count(to), iocb->ki_pos,
CODA_ACCESS_TYPE_READ);
/* If not a VASTRO file, or old client version */
if (err == -EOPNOTSUPP) {
cfi->cfi_access_intent = false;
err = 0;
}
if (err) goto finish_read;
}

err = vfs_iter_read(cfi->cfi_container, to, &iocb->ki_pos,
cfi->cfi_access_intent ? RWF_SYNC : 0);

finish_read:
venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode), to_tmp, ki_pos_tmp, CODA_ACCESS_TYPE_READ_FINISH);
return err;
if (cfi->cfi_access_intent) {
venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
to_tmp, ki_pos_tmp,
CODA_ACCESS_TYPE_READ_FINISH);
}

return err;
}

static ssize_t
Expand All @@ -136,21 +178,36 @@ coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to)
ki_pos_tmp = iocb->ki_pos;
to_tmp = iov_iter_count(to);

err = venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode), iov_iter_count(to), iocb->ki_pos, CODA_ACCESS_TYPE_WRITE);
if (err) goto finish_write;
if (cfi->cfi_access_intent) {
err = venus_access_intent(coda_inode->i_sb,
coda_i2f(coda_inode),
iov_iter_count(to), iocb->ki_pos,
CODA_ACCESS_TYPE_WRITE);
/* If not a VASTRO file, or old client version */
if (err == -EOPNOTSUPP) {
cfi->cfi_access_intent = false;
err = 0;
}
if (err) goto finish_write;
}

file_start_write(host_file);
inode_lock(coda_inode);

ret = vfs_iter_write(cfi->cfi_container, to, &iocb->ki_pos, RWF_SYNC);
ret = vfs_iter_write(cfi->cfi_container, to, &iocb->ki_pos,
cfi->cfi_access_intent ? RWF_SYNC : 0);
coda_inode->i_size = file_inode(host_file)->i_size;
coda_inode->i_blocks = (coda_inode->i_size + 511) >> 9;
coda_inode->i_mtime = coda_inode->i_ctime = current_time(coda_inode);
inode_unlock(coda_inode);
file_end_write(host_file);

finish_write:
venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode), to_tmp, ki_pos_tmp, CODA_ACCESS_TYPE_WRITE_FINISH);
if (cfi->cfi_access_intent) {
venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
to_tmp, ki_pos_tmp,
CODA_ACCESS_TYPE_WRITE_FINISH);
}
return ret;
}
#endif
Expand Down Expand Up @@ -192,11 +249,18 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
cfi->cfi_mapcount++;
spin_unlock(&cii->c_lock);

err = venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
vma->vm_end - vma->vm_start,
vma->vm_pgoff * PAGE_SIZE,
CODA_ACCESS_TYPE_MMAP);
if (err) goto error_mmap;
if (cfi->cfi_access_intent) {
err = venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
vma->vm_end - vma->vm_start,
vma->vm_pgoff * PAGE_SIZE,
CODA_ACCESS_TYPE_MMAP);
/* If not a VASTRO file, or old client version */
if (err == -EOPNOTSUPP) {
cfi->cfi_access_intent = false;
err = 0;
}
if (err) goto error_mmap;
}

err = call_mmap(host_file, vma);
error_mmap:
Expand Down Expand Up @@ -230,6 +294,8 @@ int coda_open(struct inode *coda_inode, struct file *coda_file)
cfi->cfi_magic = CODA_MAGIC;
cfi->cfi_mapcount = 0;
cfi->cfi_container = host_file;
/* Set by default. Unset on first try if not supported */
cfi->cfi_access_intent = true;

BUG_ON(coda_file->private_data != NULL);
coda_file->private_data = cfi;
Expand All @@ -250,7 +316,6 @@ int coda_release(struct inode *coda_inode, struct file *coda_file)

err = venus_close(coda_inode->i_sb, coda_i2f(coda_inode),
coda_flags, coda_file->f_cred->fsuid);

host_inode = file_inode(cfi->cfi_container);
cii = ITOC(coda_inode);

Expand Down

0 comments on commit 60477fe

Please sign in to comment.