3 #include <linux/module.h>
4 #include <linux/sched.h>
5 #include <linux/slab.h>
74 dout(
"init_file %p %p 0%o (regular)\n", inode, file,
88 dout(
"init_file %p %p 0%o (symlink)\n", inode, file,
94 dout(
"init_file %p %p 0%o (special)\n", inode, file,
104 ret = inode->
i_fop->open(inode, file);
122 struct inode *parent_inode =
NULL;
127 dout(
"open file %p is already opened\n", file);
136 dout(
"open inode %p ino %llx.%llx file %p flags %d (%d)\n", inode,
148 __ceph_get_fmode(ci, fmode);
150 return ceph_init_file(inode, file, fmode);
159 if (__ceph_is_any_real_caps(ci) &&
164 dout(
"open %p fmode %d want %s issued %s using existing\n",
167 __ceph_get_fmode(ci, fmode);
171 if ((issued & wanted) != wanted &&
172 (mds_wanted & wanted) != wanted &&
176 return ceph_init_file(inode, file, fmode);
179 __ceph_get_fmode(ci, fmode);
181 return ceph_init_file(inode, file, fmode);
186 req = prepare_open_request(inode->
i_sb, flags, 0);
199 err = ceph_init_file(inode, file, req->
r_fmode);
200 ceph_mdsc_put_request(req);
221 dout(
"atomic_open %p dentry %p '%.*s' %s flags %d mode 0%o\n",
223 d_unhashed(dentry) ?
"unhashed" :
"hashed", flags, mode);
233 req = prepare_open_request(dir->
i_sb, flags, mode);
247 if (err == 0 && (flags & O_CREAT) && !req->
r_reply_info.head->is_dentry)
250 if (d_unhashed(dentry)) {
262 dout(
"atomic_open finish_no_open on dn %p\n", dn);
265 dout(
"atomic_open finish_open on dn %p\n", dn);
270 ceph_mdsc_put_request(req);
271 dout(
"atomic_open result=%d\n", err);
280 dout(
"release inode %p file %p\n", inode, file);
301 static int striped_read(
struct inode *inode,
304 int *checkeof,
bool o_direct,
305 unsigned long buf_align)
311 int left, pages_left;
313 struct page **page_pos;
315 bool hit_stripe, was_short;
329 page_align = (pos - io_align + buf_align) & ~
PAGE_MASK;
337 page_pos, pages_left, page_align);
340 hit_stripe = this_len <
left;
341 was_short = ret >= 0 && ret < this_len;
342 dout(
"striped_read %llu~%u (read %u) got %d%s%s\n", pos, left, read,
343 ret, hit_stripe ?
" HITSTRIPE" :
"", was_short ?
" SHORT" :
"");
348 if (read < pos - off) {
349 dout(
" zero gap %llu to %llu\n", off + read, pos);
351 pos - off - read, pages);
356 page_pos += didpages;
357 pages_left -= didpages;
360 if (left && hit_stripe)
366 if (pos + left > inode->
i_size)
370 if (left > 0 && pos < inode->i_size) {
371 if (pos + left > inode->
i_size)
374 dout(
"zero tail %d\n", left);
383 dout(
"striped_read returns %d\n", ret);
393 static ssize_t ceph_sync_read(
struct file *file,
char __user *
data,
394 unsigned len, loff_t *poff,
int *checkeof)
396 struct inode *inode = file->f_dentry->d_inode;
401 dout(
"sync_read on file %p %llu~%u %s\n", file, off, len,
405 num_pages = calc_pages_for((
unsigned long)data, len);
408 num_pages = calc_pages_for(off, len);
412 return PTR_ERR(pages);
424 ret = striped_read(inode, off, len, pages, num_pages, checkeof,
438 dout(
"sync_read result %d\n", ret);
451 dout(
"sync_write_commit %p tid %llu\n", req, req->
r_tid);
466 static ssize_t ceph_sync_write(
struct file *file,
const char __user *data,
467 size_t left, loff_t *
offset)
469 struct inode *inode = file->f_dentry->d_inode;
475 long long unsigned pos;
482 unsigned long buf_align;
486 if (ceph_snap(file->f_dentry->d_inode) !=
CEPH_NOSNAP)
489 dout(
"sync_write on file %p %lld~%u %s\n", file, *offset,
493 pos = i_size_read(inode);
505 dout(
"invalidate_inode_pages2_range returned %d\n", ret);
526 page_align = (pos - io_align + buf_align) & ~
PAGE_MASK;
527 num_pages = calc_pages_for((
unsigned long)data, len);
530 num_pages = calc_pages_for(pos, len);
538 &mtime,
false, 2, page_align);
545 ret = PTR_ERR(pages);
558 ret = PTR_ERR(pages);
592 if (ret < 0 && req->r_safe_callback) {
606 ceph_osdc_put_request(req);
617 if (pos > i_size_read(inode))
634 unsigned long nr_segs, loff_t pos)
636 struct file *filp = iocb->
ki_filp;
638 loff_t *ppos = &iocb->
ki_pos;
640 struct inode *inode = filp->f_dentry->d_inode;
645 int checkeof = 0, read = 0;
647 dout(
"aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n",
648 inode,
ceph_vinop(inode), pos, (
unsigned)len, inode);
658 dout(
"aio_read %p %llx.%llx %llu~%u got cap refs on %s\n",
667 ret = ceph_sync_read(filp, base, len, ppos, &checkeof);
672 dout(
"aio_read %p %llx.%llx dropping cap refs on %s = %d\n",
676 if (checkeof && ret >= 0) {
680 if (statret == 0 && *ppos < inode->i_size) {
681 dout(
"aio_read sync_read hit hole, ppos %lld < size %lld, reading more\n", *ppos, inode->
i_size);
706 unsigned long nr_segs, loff_t pos)
708 struct file *file = iocb->
ki_filp;
710 struct inode *inode = file->f_dentry->d_inode;
713 &ceph_sb_to_client(inode->
i_sb)->
client->osdc;
714 loff_t endoff = pos + iov->
iov_len;
725 dout(
"aio_write %p %llx.%llx %llu~%u getting caps. i_size %llu\n",
736 dout(
"aio_write %p %llx.%llx %llu~%u got cap refs on %s\n",
782 dout(
"aio_write %p %llx.%llx %llu~%u dropping cap refs on %s\n",
789 dout(
"aio_write %p %llx.%llx %llu~%u got EOLDSNAPC, retrying\n",
800 static loff_t ceph_llseek(
struct file *file, loff_t offset,
int origin)
802 struct inode *inode = file->
f_mapping->host;
828 offset = file->
f_pos;
831 offset += file->
f_pos;
834 if (offset >= inode->
i_size) {
840 if (offset >= inode->
i_size) {
854 if (offset != file->
f_pos) {
867 .llseek = ceph_llseek,
870 .aio_read = ceph_aio_read,
871 .aio_write = ceph_aio_write,