From 48616a7548770cb0fd8a3e187f9adb07978621e0 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 25 Jan 2008 14:46:40 -0800 Subject: [PATCH] misc style cleanup --- src/kernel/addr.c | 12 +-- src/kernel/dir.c | 219 ++++++++++++++++++++++++--------------------- src/kernel/file.c | 112 ++++++++++++----------- src/kernel/super.c | 109 +++++++++++----------- src/kernel/super.h | 95 +++++++++++++------- 5 files changed, 301 insertions(+), 246 deletions(-) diff --git a/src/kernel/addr.c b/src/kernel/addr.c index f446d641f68c7..dc9eec56e2245 100644 --- a/src/kernel/addr.c +++ b/src/kernel/addr.c @@ -17,11 +17,12 @@ static int ceph_readpage(struct file *filp, struct page *page) struct ceph_osd_client *osdc = &ceph_inode_to_client(inode)->osdc; int err = 0; - dout(10, "ceph_readpage inode %p file %p page %p index %lu\n", + dout(10, "ceph_readpage inode %p file %p page %p index %lu\n", inode, filp, page, page->index); err = ceph_osdc_readpage(osdc, ceph_ino(inode), &ci->i_layout, page->index << PAGE_SHIFT, PAGE_SIZE, page); - if (err) goto out_unlock; + if (err) + goto out_unlock; SetPageUptodate(page); out_unlock: @@ -38,12 +39,13 @@ static int ceph_readpages(struct file *file, struct address_space *mapping, struct ceph_osd_client *osdc = &ceph_inode_to_client(inode)->osdc; int err = 0; - dout(10, "ceph_readpages inode %p file %p nr_pages %d\n", + dout(10, "ceph_readpages inode %p file %p nr_pages %d\n", inode, file, nr_pages); - + err = ceph_osdc_readpages(osdc, ceph_ino(inode), &ci->i_layout, pages, nr_pages); - if (err < 0) goto out_unlock; + if (err < 0) + goto out_unlock; // hrm //SetPageUptodate(page); diff --git a/src/kernel/dir.c b/src/kernel/dir.c index 917799947668a..4402f5794960e 100644 --- a/src/kernel/dir.c +++ b/src/kernel/dir.c @@ -30,7 +30,8 @@ retry: return ERR_PTR(-EINVAL); } } - if (len) len--; /* no leading '/' */ + if (len) + len--; /* no leading '/' */ path = kmalloc(len+1, GFP_KERNEL); if (path == NULL) @@ -44,7 +45,8 @@ retry: } else { strncpy(path + pos, temp->d_name.name, temp->d_name.len); - dout(30, "build_path_dentry path+%d: '%s'\n", pos, path + pos); + dout(30, "build_path_dentry path+%d: '%s'\n", + pos, path + pos); if (pos) path[--pos] = '/'; } @@ -56,7 +58,8 @@ retry: } } if (pos != 0) { - derr(1, "did not end path lookup where expected, namelen is %d\n", len); + derr(1, "did not end path lookup where expected, " + "namelen is %d\n", len); /* presumably this is only possible if racing with a rename of one of the parent directories (we can not lock the dentries above us to prevent this, but retrying should be harmless) */ @@ -64,7 +67,8 @@ retry: goto retry; } - dout(10, "build_path_dentry on %p build '%s' len %d\n", dentry, path, len); + dout(10, "build_path_dentry on %p build '%s' len %d\n", + dentry, path, len); *plen = len; return path; } @@ -107,38 +111,42 @@ nextfrag: struct ceph_mds_request_head *rhead; /* query mds */ - if (fi->rinfo.reply) + if (fi->rinfo.reply) ceph_mdsc_destroy_reply_info(&fi->rinfo); - - dout(10, "dir_readdir querying mds for ino %llx frag %u\n", + + dout(10, "dir_readdir querying mds for ino %llx frag %u\n", ceph_ino(inode), frag); - req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_READDIR, + req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_READDIR, ceph_ino(inode), "", 0, 0); - if (IS_ERR(req)) + if (IS_ERR(req)) return PTR_ERR(req); rhead = req->front.iov_base; rhead->args.readdir.frag = cpu_to_le32(frag); - if ((err = ceph_mdsc_do_request(mdsc, req, &fi->rinfo, 0)) < 0) + err = ceph_mdsc_do_request(mdsc, req, &fi->rinfo, 0); + if (err < 0) return err; err = le32_to_cpu(fi->rinfo.head->result); - dout(10, "dir_readdir got and parsed readdir result=%d on frag %u\n", err, frag); - if (err < 0) return err; - + dout(10, "dir_readdir got and parsed readdir result=%d" + " on frag %u\n", err, frag); + if (err < 0) + return err; + /* pre-populate dentry cache */ parent = filp->f_dentry; - for (i=0; irinfo.dir_nr; i++) { + for (i = 0; i < fi->rinfo.dir_nr; i++) { dname.name = fi->rinfo.dir_dname[i]; dname.len = fi->rinfo.dir_dname_len[i]; dname.hash = full_name_hash(dname.name, dname.len); dn = d_lookup(parent, &dname); - dout(30, "calling d_lookup on parent=%p name=%s returned %p\n", parent, dname.name, dn); + dout(30, "calling d_lookup on parent=%p name=%s" + " returned %p\n", parent, dname.name, dn); if (!dn) { dn = d_alloc(parent, &dname); if (dn == NULL) { dout(30, "d_alloc badness\n"); - break; + break; } } @@ -150,10 +158,11 @@ nextfrag: break; } } else { - in=dn->d_inode; + in = dn->d_inode; } - - if (ceph_ino(in) != le64_to_cpu(fi->rinfo.dir_in[i].in->ino)) { + + if (ceph_ino(in) != + le64_to_cpu(fi->rinfo.dir_in[i].in->ino)) { if (ceph_fill_inode(in, fi->rinfo.dir_in[i].in) < 0) { dout(30, "ceph_fill_inode badness\n"); iput(in); @@ -174,13 +183,13 @@ nextfrag: dput(dn); } } - + /* include . and .. with first fragment */ if (frag == 0) { switch (off) { case 0: dout(10, "dir_readdir off 0 -> '.'\n"); - if (filldir(dirent, ".", 1, make_fpos(0, 0), + if (filldir(dirent, ".", 1, make_fpos(0, 0), inode->i_ino, inode->i_mode >> 12) < 0) return 0; off++; @@ -188,7 +197,7 @@ nextfrag: case 1: dout(10, "dir_readdir off 1 -> '..'\n"); if (filp->f_dentry->d_parent != NULL && - filldir(dirent, "..", 2, make_fpos(0, 1), + filldir(dirent, "..", 2, make_fpos(0, 1), filp->f_dentry->d_parent->d_inode->i_ino, inode->i_mode >> 12) < 0) return 0; @@ -196,16 +205,16 @@ nextfrag: filp->f_pos++; } } else - skew = -2; + skew = -2; while (off+skew < fi->rinfo.dir_nr) { dout(10, "dir_readdir off %d -> %d / %d name '%s'\n", off, off+skew, fi->rinfo.dir_nr, fi->rinfo.dir_dname[off+skew]); - if (filldir(dirent, - fi->rinfo.dir_dname[off+skew], - fi->rinfo.dir_dname_len[off+skew], + if (filldir(dirent, + fi->rinfo.dir_dname[off+skew], + fi->rinfo.dir_dname_len[off+skew], make_fpos(frag, off), - le64_to_cpu(fi->rinfo.dir_in[off+skew].in->ino), + le64_to_cpu(fi->rinfo.dir_in[off+skew].in->ino), le32_to_cpu(fi->rinfo.dir_in[off+skew].in->mode >> 12)) < 0) { dout(20, "filldir stopping us...\n"); return 0; @@ -262,20 +271,21 @@ static struct dentry *ceph_dir_lookup(struct inode *dir, struct dentry *dentry, path = ceph_build_dentry_path(dentry, &pathlen); if (IS_ERR(path)) return ERR_PTR(PTR_ERR(path)); - req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LSTAT, + req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LSTAT, ceph_ino(dir->i_sb->s_root->d_inode), path, 0, 0); kfree(path); - if (IS_ERR(req)) + if (IS_ERR(req)) return ERR_PTR(PTR_ERR(req)); - if ((err = ceph_mdsc_do_request(mdsc, req, &rinfo, 0)) < 0) + err = ceph_mdsc_do_request(mdsc, req, &rinfo, 0); + if (err < 0) return ERR_PTR(err); err = le32_to_cpu(rinfo.head->result); dout(20, "dir_lookup result=%d\n", err); /* if there was a previous inode associated with this dentry, now there isn't one */ - if (err == -ENOENT) + if (err == -ENOENT) d_add(dentry, NULL); - else if (err < 0) + else if (err < 0) return ERR_PTR(err); if (rinfo.trace_nr > 0) { @@ -284,24 +294,22 @@ static struct dentry *ceph_dir_lookup(struct inode *dir, struct dentry *dentry, inode = ilookup(dir->i_sb, ino); - if (!inode) { + if (!inode) inode = new_inode(dir->i_sb); - } else { + else found++; - } - if (!inode) { + if (!inode) return ERR_PTR(-EACCES); - } - if ((err = ceph_fill_inode(inode, rinfo.trace_in[rinfo.trace_nr-1].in)) < 0) { + err = ceph_fill_inode(inode, + rinfo.trace_in[rinfo.trace_nr-1].in); + if (err < 0) return ERR_PTR(err); - } d_add(dentry, inode); - if (found) { + if (found) iput(inode); - } } else { dout(10, "no trace in reply? wtf.\n"); @@ -324,8 +332,8 @@ static int ceph_dir_mknod(struct inode *dir, struct dentry *dentry, int mode, de dout(5, "dir_mknod in dir %p dentry %p mode %d rdev %d\n", dir, dentry, mode, rdev); path = ceph_build_dentry_path(dentry, &pathlen); if (IS_ERR(path)) - return PTR_ERR(path); - req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_MKNOD, + return PTR_ERR(path); + req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_MKNOD, ceph_ino(dir->i_sb->s_root->d_inode), path, 0, 0); kfree(path); if (IS_ERR(req)) { @@ -335,18 +343,18 @@ static int ceph_dir_mknod(struct inode *dir, struct dentry *dentry, int mode, de rhead = req->front.iov_base; rhead->args.mknod.mode = cpu_to_le32(mode); rhead->args.mknod.rdev = cpu_to_le32(rdev); - if ((err = ceph_mdsc_do_request(mdsc, req, &rinfo, 0)) < 0) { + err = ceph_mdsc_do_request(mdsc, req, &rinfo, 0); + if (err < 0) { d_drop(dentry); return err; } - + err = le32_to_cpu(rinfo.head->result); if (err == 0) { err = ceph_fill_trace(dir->i_sb, &rinfo, &inode, NULL); - if (err < 0) { + if (err < 0) goto done; - } if (inode == NULL) { /* TODO handle this one */ @@ -373,26 +381,26 @@ static int ceph_dir_symlink(struct inode *dir, struct dentry *dentry, const char dout(5, "dir_symlink in dir %p dentry %p to '%s'\n", dir, dentry, dest); path = ceph_build_dentry_path(dentry, &pathlen); if (IS_ERR(path)) - return PTR_ERR(path); - req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SYMLINK, + return PTR_ERR(path); + req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SYMLINK, ceph_ino(dir->i_sb->s_root->d_inode), path, 0, dest); kfree(path); if (IS_ERR(req)) { d_drop(dentry); return PTR_ERR(req); } - if ((err = ceph_mdsc_do_request(mdsc, req, &rinfo, 0)) < 0) { + err = ceph_mdsc_do_request(mdsc, req, &rinfo, 0); + if (err < 0) { d_drop(dentry); return err; } - + err = le32_to_cpu(rinfo.head->result); if (err == 0) { err = ceph_fill_trace(dir->i_sb, &rinfo, &inode, NULL); - if (err < 0) { + if (err < 0) goto done; - } if (inode == NULL) { /* TODO handle this one */ @@ -420,8 +428,8 @@ static int ceph_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode) dout(5, "dir_mkdir in dir %p dentry %p mode %d\n", dir, dentry, mode); path = ceph_build_dentry_path(dentry, &pathlen); if (IS_ERR(path)) - return PTR_ERR(path); - req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_MKDIR, + return PTR_ERR(path); + req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_MKDIR, ceph_ino(dir->i_sb->s_root->d_inode), path, 0, 0); kfree(path); if (IS_ERR(req)) { @@ -429,20 +437,20 @@ static int ceph_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode) return PTR_ERR(req); } rhead = req->front.iov_base; - rhead->args.mkdir.mode = cpu_to_le32(mode); - if ((err = ceph_mdsc_do_request(mdsc, req, &rinfo, 0)) < 0) { + rhead->args.mkdir.mode = cpu_to_le32(mode); + err = ceph_mdsc_do_request(mdsc, req, &rinfo, 0); + if (err < 0) { d_drop(dentry); return err; } - + err = le32_to_cpu(rinfo.head->result); if (err == 0) { /* inode_dec_link_count(inode); */ err = ceph_fill_trace(dir->i_sb, &rinfo, &inode, NULL); - if (err < 0) { + if (err < 0) goto done_mkdir; - } if (inode == NULL) { /* TODO handle this one */ @@ -466,20 +474,22 @@ static int ceph_dir_unlink(struct inode *dir, struct dentry *dentry) char *path; int pathlen; int err; - int op = ((dentry->d_inode->i_mode & S_IFMT) == S_IFDIR) ? CEPH_MDS_OP_RMDIR:CEPH_MDS_OP_UNLINK; - + int op = ((dentry->d_inode->i_mode & S_IFMT) == S_IFDIR) ? + CEPH_MDS_OP_RMDIR : CEPH_MDS_OP_UNLINK; + dout(5, "dir_unlink/rmdir in dir %p dentry %p inode %p\n", dir, dentry, inode); path = ceph_build_dentry_path(dentry, &pathlen); if (IS_ERR(path)) return PTR_ERR(path); - req = ceph_mdsc_create_request(mdsc, op, + req = ceph_mdsc_create_request(mdsc, op, ceph_ino(dir->i_sb->s_root->d_inode), path, 0, 0); kfree(path); - if (IS_ERR(req)) + if (IS_ERR(req)) return PTR_ERR(req); - if ((err = ceph_mdsc_do_request(mdsc, req, &rinfo, 0)) < 0) + err = ceph_mdsc_do_request(mdsc, req, &rinfo, 0); + if (err < 0) return err; - + err = le32_to_cpu(rinfo.head->result); if (err == 0) { inode_dec_link_count(inode); @@ -499,11 +509,11 @@ static int ceph_dir_rename(struct inode *old_dir, struct dentry *old_dentry, char *oldpath, *newpath; int oldpathlen, newpathlen; int err; - - dout(5, "dir_rename in dir %p dentry %p to dir %p dentry %p\n", + + dout(5, "dir_rename in dir %p dentry %p to dir %p dentry %p\n", old_dir, old_dentry, new_dir, new_dentry); oldpath = ceph_build_dentry_path(old_dentry, &oldpathlen); - if (IS_ERR(oldpath)) + if (IS_ERR(oldpath)) return PTR_ERR(oldpath); newpath = ceph_build_dentry_path(new_dentry, &newpathlen); if (IS_ERR(newpath)) { @@ -511,15 +521,16 @@ static int ceph_dir_rename(struct inode *old_dir, struct dentry *old_dentry, return PTR_ERR(newpath); } req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_RENAME, - ceph_ino(root->d_inode), oldpath, + ceph_ino(root->d_inode), oldpath, ceph_ino(root->d_inode), newpath); kfree(oldpath); kfree(newpath); - if (IS_ERR(req)) + if (IS_ERR(req)) return PTR_ERR(req); - if ((err = ceph_mdsc_do_request(mdsc, req, &rinfo, 0)) < 0) + err = ceph_mdsc_do_request(mdsc, req, &rinfo, 0); + if (err < 0) return err; - + err = le32_to_cpu(rinfo.head->result); if (err == 0) { /* FIXME update dir mtime etc. from reply trace */ @@ -531,42 +542,42 @@ static int ceph_dir_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd) { - struct ceph_mds_client *mdsc = &ceph_inode_to_client(dir)->mdsc; - ceph_ino_t pathbase; - char *path; - int pathlen; - struct ceph_msg *req; - struct ceph_mds_request_head *rhead; - struct ceph_mds_reply_info rinfo; - struct ceph_mds_session *session; - int err; + struct ceph_mds_client *mdsc = &ceph_inode_to_client(dir)->mdsc; + ceph_ino_t pathbase; + char *path; + int pathlen; + struct ceph_msg *req; + struct ceph_mds_request_head *rhead; + struct ceph_mds_reply_info rinfo; + struct ceph_mds_session *session; + int err; struct inode *inode; - - dout(5, "create in dir %p dentry %p name '%s' flags %d\n", dir, dentry, dentry->d_name.name, mode); - pathbase = ceph_ino(dir->i_sb->s_root->d_inode); - path = ceph_build_dentry_path(dentry, &pathlen); - if (IS_ERR(path)) - return PTR_ERR(path); - req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_MKNOD, pathbase, path, 0, 0); - kfree(path); - if (IS_ERR(req)) - return PTR_ERR(req); - rhead = req->front.iov_base; - rhead->args.mknod.mode = cpu_to_le32(mode); - rhead->args.mknod.rdev = 0; - if ((err = ceph_mdsc_do_request(mdsc, req, &rinfo, &session)) < 0) - return err; - - dout(10, "create got and parsed result\n"); - + + dout(5, "create in dir %p dentry %p name '%s' flags %d\n", dir, dentry, dentry->d_name.name, mode); + pathbase = ceph_ino(dir->i_sb->s_root->d_inode); + path = ceph_build_dentry_path(dentry, &pathlen); + if (IS_ERR(path)) + return PTR_ERR(path); + req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_MKNOD, pathbase, path, 0, 0); + kfree(path); + if (IS_ERR(req)) + return PTR_ERR(req); + rhead = req->front.iov_base; + rhead->args.mknod.mode = cpu_to_le32(mode); + rhead->args.mknod.rdev = 0; + err = ceph_mdsc_do_request(mdsc, req, &rinfo, &session); + if (err < 0) + return err; + + dout(10, "create got and parsed result\n"); + err = le32_to_cpu(rinfo.head->result); if (err == 0) { err = ceph_fill_trace(dir->i_sb, &rinfo, &inode, NULL); - - if (err < 0) { + + if (err < 0) goto done_create; - } - + if (inode == NULL) { err = -ENOMEM; goto done_create; diff --git a/src/kernel/file.c b/src/kernel/file.c index a321265fd186c..1a982559f7e63 100644 --- a/src/kernel/file.c +++ b/src/kernel/file.c @@ -9,8 +9,10 @@ int ceph_debug_file = 50; /* * if err==0, caller is responsible for a put_session on *psession */ -int do_open_request(struct super_block *sb, struct dentry *dentry, int flags, int create_mode, - struct ceph_mds_session **psession, struct ceph_mds_reply_info *rinfo) +int do_open_request(struct super_block *sb, struct dentry *dentry, + int flags, int create_mode, + struct ceph_mds_session **psession, + struct ceph_mds_reply_info *rinfo) { struct ceph_client *client = ceph_sb_to_client(sb); struct ceph_mds_client *mdsc = &client->mdsc; @@ -21,19 +23,22 @@ int do_open_request(struct super_block *sb, struct dentry *dentry, int flags, in struct ceph_mds_request_head *rhead; int err; - dout(5, "open dentry %p name '%s' flags %d\n", dentry, dentry->d_name.name, flags); + dout(5, "open dentry %p name '%s' flags %d\n", dentry, + dentry->d_name.name, flags); pathbase = ceph_ino(sb->s_root->d_inode); path = ceph_build_dentry_path(dentry, &pathlen); - if (IS_ERR(path)) + if (IS_ERR(path)) return PTR_ERR(path); - req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_OPEN, pathbase, path, 0, 0); + req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_OPEN, pathbase, path, + 0, 0); kfree(path); - if (IS_ERR(req)) + if (IS_ERR(req)) return PTR_ERR(req); rhead = req->front.iov_base; rhead->args.open.flags = cpu_to_le32(flags); rhead->args.open.mode = cpu_to_le32(create_mode); - if ((err = ceph_mdsc_do_request(mdsc, req, rinfo, psession)) < 0) + err = ceph_mdsc_do_request(mdsc, req, rinfo, psession); + if (err < 0) return err; return 0; } @@ -42,14 +47,15 @@ int do_open_request(struct super_block *sb, struct dentry *dentry, int flags, in * add cap. also set up private_data for holding readdir results * if O_DIRECTORY. */ -int proc_open_reply(struct inode *inode, struct file *file, - struct ceph_mds_session *session, struct ceph_mds_reply_info *rinfo) +int proc_open_reply(struct inode *inode, struct file *file, + struct ceph_mds_session *session, + struct ceph_mds_reply_info *rinfo) { struct ceph_inode_cap *cap; struct ceph_file_info *cf; - cap = ceph_add_cap(inode, session, - le32_to_cpu(rinfo->head->file_caps), + cap = ceph_add_cap(inode, session, + le32_to_cpu(rinfo->head->file_caps), le32_to_cpu(rinfo->head->file_caps_seq)); if (file->f_flags & O_DIRECTORY) { @@ -91,22 +97,24 @@ int ceph_open(struct inode *inode, struct file *file) struct ceph_file_info *cf = file->private_data; int err; - dout(5, "ceph_open inode %p ino %llx file %p\n", inode, + dout(5, "ceph_open inode %p ino %llx file %p\n", inode, ceph_ino(inode), file); if (cf) { /* the file is already opened */ return 0; } - + /* - if (file->f_flags == O_DIRECTORY && ... ) + if (file->f_flags == O_DIRECTORY && ... ) cap = ceph_find_cap(inode, 0); */ if (!cap) { - dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias); - err = do_open_request(inode->i_sb, dentry, file->f_flags, 0, &session, &rinfo); - if (err < 0) + dentry = list_entry(inode->i_dentry.next, struct dentry, + d_alias); + err = do_open_request(inode->i_sb, dentry, file->f_flags, 0, + &session, &rinfo); + if (err < 0) return err; err = proc_open_reply(inode, file, session, &rinfo); ceph_mdsc_put_session(session); @@ -116,15 +124,15 @@ int ceph_open(struct inode *inode, struct file *file) err = ceph_open_init_private_data(inode, file); - if (err < 0) { + if (err < 0) return err; - } - + dout(5, "ceph_open success, %llx\n", ceph_ino(inode)); return 0; } -int ceph_lookup_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd) +int ceph_lookup_open(struct inode *dir, struct dentry *dentry, + struct nameidata *nd) { struct ceph_mds_reply_info rinfo; struct ceph_mds_session *session; @@ -134,18 +142,21 @@ int ceph_lookup_open(struct inode *dir, struct dentry *dentry, struct nameidata int found = 0; int err; - dout(5, "ceph_lookup_open in dir %p dentry %p '%s'\n", dir, dentry, dentry->d_name.name); - err = do_open_request(dir->i_sb, dentry, nd->intent.open.flags, nd->intent.open.create_mode, + dout(5, "ceph_lookup_open in dir %p dentry %p '%s'\n", dir, dentry, + dentry->d_name.name); + err = do_open_request(dir->i_sb, dentry, nd->intent.open.flags, + nd->intent.open.create_mode, &session, &rinfo); if (err < 0) return err; err = le32_to_cpu(rinfo.head->result); dout(20, "ceph_lookup_open result=%d\n", err); - /* if there was a previous inode associated with this dentry, now there isn't one */ - if (err == -ENOENT) + /* if there was a previous inode associated with this dentry, + * now there isn't one */ + if (err == -ENOENT) d_add(dentry, NULL); - if (err < 0) + if (err < 0) goto out; if (rinfo.trace_nr == 0) { derr(0, "wtf, no trace from mds\n"); @@ -157,7 +168,7 @@ int ceph_lookup_open(struct inode *dir, struct dentry *dentry, struct nameidata ino = le64_to_cpu(rinfo.trace_in[rinfo.trace_nr-1].in->ino); dout(10, "got and parsed stat result, ino %lu\n", ino); inode = ilookup(dir->i_sb, ino); - if (!inode) + if (!inode) inode = new_inode(dir->i_sb); else found++; @@ -165,19 +176,19 @@ int ceph_lookup_open(struct inode *dir, struct dentry *dentry, struct nameidata err = -EACCES; goto out; } - - if ((err = ceph_fill_inode(inode, rinfo.trace_in[rinfo.trace_nr-1].in)) < 0) + + err = ceph_fill_inode(inode, rinfo.trace_in[rinfo.trace_nr-1].in); + if (err < 0) goto out; d_add(dentry, inode); - if (found) + if (found) iput(inode); /* finish the open */ err = proc_open_reply(inode, file, session, &rinfo); - if (err == 0) { + if (err == 0) err = ceph_open_init_private_data(inode, file); - } out: ceph_mdsc_put_session(session); return err; @@ -188,11 +199,11 @@ int ceph_release(struct inode *inode, struct file *file) struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_file_info *cf = file->private_data; int mode, wanted; - + dout(5, "ceph_release inode %p file %p\n", inode, file); atomic_dec(&ci->i_cap_count); - - if (cf->rinfo.reply) + + if (cf->rinfo.reply) ceph_mdsc_destroy_reply_info(&cf->rinfo); kfree(cf); @@ -218,32 +229,36 @@ const struct inode_operations ceph_file_iops = { * totally naive write. just to get things sort of working. * ugly hack! */ -ssize_t ceph_silly_write(struct file *file, const char __user * data, - size_t count, loff_t * offset) +ssize_t ceph_silly_write(struct file *file, const char __user *data, + size_t count, loff_t *offset) { struct inode *inode = file->f_path.dentry->d_inode; struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_osd_client *osdc = &ceph_inode_to_client(inode)->osdc; int ret = 0; int did = 0; - - dout(10, "silly_write on file %p %lld~%u\n", file, *offset, (unsigned)count); - + + dout(10, "silly_write on file %p %lld~%u\n", file, *offset, + (unsigned)count); + /* ignore caps, for now. */ /* this is an ugly hack */ while (count > 0) { - ret = ceph_osdc_silly_write(osdc, ceph_ino(inode), &ci->i_layout, count, *offset, data); + ret = ceph_osdc_silly_write(osdc, ceph_ino(inode), + &ci->i_layout, + count, *offset, data); dout(10, "ret is %d\n", ret); if (ret > 0) { did += ret; *offset += ret; data += ret; count -= ret; - dout(10, "did %d bytes, ret now %d, %u left\n", did, ret, (unsigned)count); - } else if (did) + dout(10, "did %d bytes, ret now %d, %u left\n", + did, ret, (unsigned)count); + } else if (did) break; - else + else return ret; } @@ -252,7 +267,7 @@ ssize_t ceph_silly_write(struct file *file, const char __user * data, ci->i_wr_size = inode->i_size = *offset; inode->i_blocks = (inode->i_size + 512 - 1) >> 9; dout(10, "extending file size to %d\n", (int)inode->i_size); - } + } spin_unlock(&inode->i_lock); invalidate_inode_pages2(inode->i_mapping); return ret; @@ -267,11 +282,4 @@ const struct file_operations ceph_file_fops = { .aio_read = generic_file_aio_read, .aio_write = generic_file_aio_write, .mmap = generic_file_mmap, -/* .read = ceph_file_read, - .write = ceph_file_write, - .open = ceph_file_open, -// .release = ceph_dir_release, - .lock = ceph_file_lock, - .mmap = generic_file_mmap, -*/ }; diff --git a/src/kernel/super.c b/src/kernel/super.c index 6fc7e26cd5555..be3613fa76995 100644 --- a/src/kernel/super.c +++ b/src/kernel/super.c @@ -21,12 +21,13 @@ int ceph_super_debug = 50; * super ops */ -static int ceph_write_inode(struct inode * inode, int unused) +static int ceph_write_inode(struct inode *inode, int unused) { struct ceph_inode_info *ci = ceph_inode(inode); if (memcmp(&ci->i_old_atime, &inode->i_atime, sizeof(struct timeval))) { - dout(30, "ceph_write_inode %llx .. atime updated\n", ceph_ino(inode)); + dout(30, "ceph_write_inode %llx .. atime updated\n", + ceph_ino(inode)); /* eventually push this async to mds ... */ } return 0; @@ -45,7 +46,8 @@ static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf) int err; dout(30, "ceph_statfs\n"); - if ((err = ceph_monc_do_statfs(&client->monc, &st)) < 0) + err = ceph_monc_do_statfs(&client->monc, &st); + if (err < 0) return err; /* fill in kstatfs */ @@ -59,7 +61,7 @@ static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf) /* fsid? */ buf->f_namelen = 1024; buf->f_frsize = 4096; - + return 0; } @@ -75,9 +77,9 @@ static int ceph_show_options(struct seq_file *m, struct vfsmount *mnt) struct ceph_mount_args *args = &client->mount_args; if (ceph_debug != 0) - seq_printf(m, ",debug=%d", ceph_debug); - if (args->flags & CEPH_MOUNT_FSID) - seq_printf(m, ",fsidmajor=%llu,fsidminor%llu", + seq_printf(m, ",debug=%d", ceph_debug); + if (args->flags & CEPH_MOUNT_FSID) + seq_printf(m, ",fsidmajor=%llu,fsidminor%llu", args->fsid.major, args->fsid.minor); if (args->flags & CEPH_MOUNT_NOSHARE) seq_puts(m, ",noshare"); @@ -114,16 +116,16 @@ static struct inode *ceph_alloc_inode(struct super_block *sb) ci->i_caps = ci->i_caps_static; atomic_set(&ci->i_cap_count, 0); - for (i=0; i<4; i++) + for (i = 0; i < 4; i++) ci->i_nr_by_mode[i] = 0; ci->i_cap_wanted = 0; - + ci->i_wr_size = 0; ci->i_wr_mtime.tv_sec = 0; ci->i_wr_mtime.tv_nsec = 0; ci->i_hashval = 0; - + return &ci->vfs_inode; } @@ -131,13 +133,12 @@ static void ceph_destroy_inode(struct inode *inode) { struct ceph_inode_info *ci = ceph_inode(inode); - dout(30, "destroy_inode %p ino %lu=%llx\n", inode, + dout(30, "destroy_inode %p ino %lu=%llx\n", inode, inode->i_ino, ceph_ino(inode)); - if (ci->i_caps != ci->i_caps_static) + if (ci->i_caps != ci->i_caps_static) kfree(ci->i_caps); - if (ci->i_symlink) - kfree(ci->i_symlink); + kfree(ci->i_symlink); kmem_cache_free(ceph_inode_cachep, ci); } @@ -174,7 +175,7 @@ static const struct super_operations ceph_sops = { .alloc_inode = ceph_alloc_inode, .destroy_inode = ceph_destroy_inode, .write_inode = ceph_write_inode, -// .sync_fs = ceph_syncfs, +/* .sync_fs = ceph_syncfs, */ .put_super = ceph_put_super, .show_options = ceph_show_options, .statfs = ceph_statfs, @@ -185,12 +186,12 @@ static const struct super_operations ceph_sops = { -/* +/* * mount options */ enum { - Opt_fsidmajor, + Opt_fsidmajor, Opt_fsidminor, Opt_debug, Opt_debug_msgr, @@ -224,25 +225,23 @@ static int parse_ip(const char *c, int len, struct ceph_entity_addr *addr) const char *p = c; dout(15, "parse_ip on '%s' len %d\n", c, len); - for (i=0; *p && i<4; i++) { + for (i = 0; *p && i < 4; i++) { v = 0; - //dout(30, " i=%d at %s\n", i, p); while (*p && *p != '.' && p < c+len) { if (*p < '0' || *p > '9') goto bad; v = (v * 10) + (*p - '0'); p++; } - //dout(30, " v = %d\n", v); ip = (ip << 8) + v; - if (!*p) + if (!*p) break; p++; } - if (p < c+len) + if (p < c+len) goto bad; - *(__u32*)&addr->ipaddr.sin_addr.s_addr = htonl(ip); + *(__be32 *)&addr->ipaddr.sin_addr.s_addr = htonl(ip); dout(15, "parse_ip got %u.%u.%u.%u\n", ip >> 24, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff); return 0; @@ -252,7 +251,8 @@ bad: return -EINVAL; } -static int parse_mount_args(int flags, char *options, const char *dev_name, struct ceph_mount_args *args) +static int parse_mount_args(int flags, char *options, const char *dev_name, + struct ceph_mount_args *args) { char *c; int len, err; @@ -271,29 +271,30 @@ static int parse_mount_args(int flags, char *options, const char *dev_name, stru return -EINVAL; /* get mon ip */ - /* er, just one for now. later, comma-separate... */ + /* er, just one for now. later, comma-separate... */ len = c - dev_name; - if ((err = parse_ip(dev_name, len, &args->mon_addr[0])) < 0) + err = parse_ip(dev_name, len, &args->mon_addr[0]); + if (err < 0) return err; args->mon_addr[0].ipaddr.sin_family = AF_INET; args->mon_addr[0].ipaddr.sin_port = htons(CEPH_MON_PORT); args->mon_addr[0].erank = 0; args->mon_addr[0].nonce = 0; args->num_mon = 1; - + /* path on server */ c++; while (*c == '/') c++; /* remove leading '/'(s) */ if (strlen(c) >= sizeof(args->path)) return -ENAMETOOLONG; strcpy(args->path, c); - + dout(15, "server path '%s'\n", args->path); - + /* parse mount options */ while ((c = strsep(&options, ",")) != NULL) { int token, intval, ret, i; - if (!*c) + if (!*c) continue; token = match_token(c, arg_tokens, argstr); if (token < Opt_ip) { @@ -313,8 +314,9 @@ static int parse_mount_args(int flags, char *options, const char *dev_name, stru break; case Opt_monport: dout(25, "parse_mount_args monport=%d\n", intval); - for (i=0; inum_mon; i++) - args->mon_addr[i].ipaddr.sin_port = htons(intval); + for (i = 0; i < args->num_mon; i++) + args->mon_addr[i].ipaddr.sin_port = + htons(intval); break; case Opt_debug: ceph_debug = intval; @@ -332,9 +334,10 @@ static int parse_mount_args(int flags, char *options, const char *dev_name, stru args->my_addr.ipaddr.sin_port = htons(intval); break; case Opt_ip: - if ((err = parse_ip(argstr[0].from, - argstr[0].to-argstr[0].from, - &args->my_addr)) < 0) + err = parse_ip(argstr[0].from, + argstr[0].to-argstr[0].from, + &args->my_addr); + if (err < 0) return err; break; default: @@ -362,7 +365,7 @@ static int ceph_set_super(struct super_block *s, void *data) if (IS_ERR(client)) return PTR_ERR(client); s->s_fs_info = client; - + /* fill sbinfo */ s->s_op = &ceph_sops; memcpy(&client->mount_args, args, sizeof(*args)); @@ -384,7 +387,7 @@ bail: */ static int ceph_compare_super(struct super_block *sb, void *data) { - struct ceph_mount_args *args = (struct ceph_mount_args*)data; + struct ceph_mount_args *args = (struct ceph_mount_args *)data; struct ceph_client *other = ceph_sb_to_client(sb); int i; dout(10, "ceph_compare_super %p\n", sb); @@ -397,8 +400,8 @@ static int ceph_compare_super(struct super_block *sb, void *data) } } else { /* do we share (a) monitor? */ - for (i=0; inum_mon; i++) - if (ceph_monmap_contains(other->monc.monmap, + for (i = 0; i < args->num_mon; i++) + if (ceph_monmap_contains(other->monc.monmap, &args->mon_addr[i])) break; if (i == args->num_mon) { @@ -415,7 +418,8 @@ static int ceph_compare_super(struct super_block *sb, void *data) } static int ceph_get_sb(struct file_system_type *fs_type, - int flags, const char *dev_name, void *data, struct vfsmount *mnt) + int flags, const char *dev_name, void *data, + struct vfsmount *mnt) { struct super_block *sb; struct ceph_mount_args *mount_args; @@ -427,14 +431,14 @@ static int ceph_get_sb(struct file_system_type *fs_type, dout(25, "ceph_get_sb\n"); mount_args = kmalloc(sizeof(struct ceph_mount_args), GFP_KERNEL); - + err = parse_mount_args(flags, data, dev_name, mount_args); - if (err < 0) + if (err < 0) goto out; if (mount_args->flags & CEPH_MOUNT_NOSHARE) compare_super = 0; - + /* superblock */ sb = sget(fs_type, compare_super, ceph_set_super, mount_args); if (IS_ERR(sb)) { @@ -443,9 +447,10 @@ static int ceph_get_sb(struct file_system_type *fs_type, } client = ceph_sb_to_client(sb); - if ((err = ceph_mount(client, mount_args, &droot)) < 0) + err = ceph_mount(client, mount_args, &droot); + if (err < 0) goto out_splat; - + dout(30, "ceph_get_sb %p finishing\n", sb); mnt->mnt_sb = sb; mnt->mnt_root = droot; @@ -453,7 +458,7 @@ static int ceph_get_sb(struct file_system_type *fs_type, dout(22, "droot ino %llx\n", ceph_ino(droot->d_inode)); return 0; - + out_splat: up_write(&sb->s_umount); deactivate_super(sb); @@ -490,11 +495,13 @@ static int __init init_ceph(void) int ret = 0; dout(1, "init_ceph\n"); - if (!(ret = init_inodecache())) { - if ((ret = register_filesystem(&ceph_fs_type))) { - destroy_inodecache(); - } - } + ret = init_inodecache(); + if (ret) + goto out; + ret = register_filesystem(&ceph_fs_type); + if (ret) + destroy_inodecache(); +out: return ret; } diff --git a/src/kernel/super.h b/src/kernel/super.h index 225ba7496bfd1..c3fb6226e350b 100644 --- a/src/kernel/super.h +++ b/src/kernel/super.h @@ -16,8 +16,14 @@ extern int ceph_debug_msgr; extern int ceph_debug_mdsc; extern int ceph_debug_osdc; -# define dout(x, args...) do { if (x <= (ceph_debug ? ceph_debug : DOUT_VAR)) printk(KERN_INFO "ceph_" DOUT_PREFIX args); } while (0) -# define derr(x, args...) do { if (x <= (ceph_debug ? ceph_debug : DOUT_VAR)) printk(KERN_ERR "ceph_" DOUT_PREFIX args); } while (0) +# define dout(x, args...) do { \ + if (x <= (ceph_debug ? ceph_debug : DOUT_VAR)) \ + printk(KERN_INFO "ceph_" DOUT_PREFIX args); \ + } while (0) +# define derr(x, args...) do { \ + if (x <= (ceph_debug ? ceph_debug : DOUT_VAR)) \ + printk(KERN_ERR "ceph_" DOUT_PREFIX args); \ + } while (0) #define CEPH_SUPER_MAGIC 0xc364c0de /* whatev */ @@ -48,10 +54,10 @@ enum { UNMOUNTED }; -/* +/* * per-filesystem client state - * - * possibly shared by multiple mount points, if they are + * + * possibly shared by multiple mount points, if they are * mounting the same ceph filesystem/cluster. */ struct ceph_client { @@ -72,7 +78,7 @@ struct ceph_client { /* lets ignore all this until later */ spinlock_t sb_lock; - int num_sb; /* reference count (for each sb_info that points to me) */ + int num_sb; /* ref count (for each sb_info that points to me) */ struct list_head sb_list; }; @@ -122,7 +128,7 @@ struct ceph_inode_info { struct ceph_frag_tree_head *i_fragtree, i_fragtree_static[1]; int i_frag_map_nr; struct ceph_inode_frag_map_item *i_frag_map, i_frag_map_static[1]; - + int i_nr_caps, i_max_caps; struct ceph_inode_cap *i_caps; struct ceph_inode_cap i_caps_static[STATIC_CAPS]; @@ -135,7 +141,7 @@ struct ceph_inode_info { struct timespec i_old_atime; unsigned long i_hashval; - + struct inode vfs_inode; /* at end */ }; @@ -150,16 +156,18 @@ static inline struct ceph_inode_info *ceph_inode(struct inode *inode) static inline ino_t ceph_ino_to_ino(u64 cephino) { ino_t ino = (ino_t)cephino; - if (sizeof(ino_t) < sizeof(u64)) + if (sizeof(ino_t) < sizeof(u64)) ino ^= cephino >> (sizeof(u64)-sizeof(ino_t)) * 8; return ino; } -static inline void ceph_set_ino(struct inode *inode, __u64 ino) { +static inline void ceph_set_ino(struct inode *inode, __u64 ino) +{ struct ceph_inode_info *ci = ceph_inode(inode); ci->i_ceph_ino = ino; inode->i_ino = ceph_ino_to_ino(ino); } -static inline u64 ceph_ino(struct inode *inode) { +static inline u64 ceph_ino(struct inode *inode) +{ struct ceph_inode_info *ci = ceph_inode(inode); return ci->i_ceph_ino; } @@ -167,23 +175,31 @@ static inline u64 ceph_ino(struct inode *inode) { /* * caps helpers */ -static inline int ceph_caps_issued(struct ceph_inode_info *ci) { +static inline int ceph_caps_issued(struct ceph_inode_info *ci) +{ int i, issued = 0; - for (i=0; ii_nr_caps; i++) + for (i = 0; i < ci->i_nr_caps; i++) issued |= ci->i_caps[i].caps; return issued; } -static inline int ceph_caps_wanted(struct ceph_inode_info *ci) { +static inline int ceph_caps_wanted(struct ceph_inode_info *ci) +{ int want = 0; - if (ci->i_nr_by_mode[0]) want |= CEPH_CAP_PIN; - if (ci->i_nr_by_mode[1]) want |= CEPH_CAP_RD|CEPH_CAP_RDCACHE; - if (ci->i_nr_by_mode[2]) want |= CEPH_CAP_RD|CEPH_CAP_RDCACHE|CEPH_CAP_WR|CEPH_CAP_WRBUFFER; - if (ci->i_nr_by_mode[3]) want |= CEPH_CAP_WR|CEPH_CAP_WRBUFFER; + if (ci->i_nr_by_mode[0]) + want |= CEPH_CAP_PIN; + if (ci->i_nr_by_mode[1]) + want |= CEPH_CAP_RD|CEPH_CAP_RDCACHE; + if (ci->i_nr_by_mode[2]) + want |= CEPH_CAP_RD|CEPH_CAP_RDCACHE| + CEPH_CAP_WR|CEPH_CAP_WRBUFFER; + if (ci->i_nr_by_mode[3]) + want |= CEPH_CAP_WR|CEPH_CAP_WRBUFFER; return want; } -static inline int ceph_caps_used(struct ceph_inode_info *ci) { +static inline int ceph_caps_used(struct ceph_inode_info *ci) +{ return 0; /* FIXME */ } @@ -197,23 +213,23 @@ static inline int ceph_file_mode(int flags) return FILE_MODE_WRONLY; if ((flags & O_RDONLY) == O_RDONLY) return FILE_MODE_RDONLY; - BUG_ON(1); + BUG_ON(1); } static inline struct ceph_client *ceph_inode_to_client(struct inode *inode) { - return (struct ceph_client*)inode->i_sb->s_fs_info; + return (struct ceph_client *)inode->i_sb->s_fs_info; } static inline struct ceph_client *ceph_sb_to_client(struct super_block *sb) { - return (struct ceph_client*)sb->s_fs_info; + return (struct ceph_client *)sb->s_fs_info; } /* * keep readdir buffers attached to file->private_data */ struct ceph_file_info { - u32 frag; /* just one frag at a time; screw seek_dir() on large dirs */ + u32 frag; /* one frag at a time; screw seek_dir() on large dirs */ struct ceph_mds_reply_info rinfo; }; @@ -225,7 +241,7 @@ struct ceph_file_info { static inline int calc_pages_for(int len, int off) { int nr = 0; - if (len == 0) + if (len == 0) return 0; if (off + len < PAGE_SIZE) return 1; @@ -241,23 +257,31 @@ static inline int calc_pages_for(int len, int off) /* client.c */ -extern struct ceph_client *ceph_create_client(struct ceph_mount_args *args, struct super_block *sb); +extern struct ceph_client *ceph_create_client(struct ceph_mount_args *args, + struct super_block *sb); extern void ceph_destroy_client(struct ceph_client *cl); extern int ceph_mount(struct ceph_client *client, struct ceph_mount_args *args, - struct dentry **pmnt_root); + struct dentry **pmnt_root); /* inode.c */ -extern int ceph_get_inode(struct super_block *sb, u64 ino, struct inode **pinode); -extern int ceph_fill_inode(struct inode *inode, struct ceph_mds_reply_inode *info); +extern int ceph_get_inode(struct super_block *sb, u64 ino, + struct inode **pinode); +extern int ceph_fill_inode(struct inode *inode, + struct ceph_mds_reply_inode *info); extern struct ceph_inode_cap *ceph_find_cap(struct inode *inode, int want); -extern struct ceph_inode_cap *ceph_add_cap(struct inode *inode, struct ceph_mds_session *session, u32 cap, u32 seq); +extern struct ceph_inode_cap *ceph_add_cap(struct inode *inode, + struct ceph_mds_session *session, + u32 cap, u32 seq); extern void ceph_remove_cap(struct ceph_inode_info *ci, int mds); extern void ceph_remove_caps(struct ceph_inode_info *ci); -extern int ceph_handle_cap_grant(struct inode *inode, struct ceph_mds_file_caps *grant, struct ceph_mds_session *session); +extern int ceph_handle_cap_grant(struct inode *inode, + struct ceph_mds_file_caps *grant, + struct ceph_mds_session *session); extern int ceph_setattr(struct dentry *dentry, struct iattr *attr); -extern int ceph_inode_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat); +extern int ceph_inode_getattr(struct vfsmount *mnt, struct dentry *dentry, + struct kstat *stat); /* addr.c */ extern const struct address_space_operations ceph_aops; @@ -267,15 +291,18 @@ extern const struct inode_operations ceph_file_iops; extern const struct file_operations ceph_file_fops; extern const struct address_space_operations ceph_aops; extern int ceph_open(struct inode *inode, struct file *file); -extern int ceph_lookup_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd); +extern int ceph_lookup_open(struct inode *dir, struct dentry *dentry, + struct nameidata *nd); extern int ceph_release(struct inode *inode, struct file *filp); /* dir.c */ extern const struct inode_operations ceph_dir_iops; extern const struct file_operations ceph_dir_fops; extern char *ceph_build_dentry_path(struct dentry *dentry, int *len); -extern int ceph_fill_trace(struct super_block *sb, struct ceph_mds_reply_info *prinfo, - struct inode **lastinode, struct dentry **lastdentry); +extern int ceph_fill_trace(struct super_block *sb, + struct ceph_mds_reply_info *prinfo, + struct inode **lastinode, + struct dentry **lastdentry); #endif /* _FS_CEPH_CEPH_H */ -- 2.39.5