From d4ca548b728bf29529e81a35eaa7024da30b2e2c Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 14 Jan 2008 12:18:27 -0800 Subject: [PATCH] mknod, symlink work --- src/kernel/dir.c | 103 +++++++++++++++++++++++++++++++++- src/kernel/inode.c | 63 +++++++++------------ src/kernel/super.c | 6 +- src/kernel/super.h | 2 + src/mds/CInode.cc | 2 +- src/mds/Server.cc | 6 +- src/messages/MClientRequest.h | 2 +- 7 files changed, 141 insertions(+), 43 deletions(-) diff --git a/src/kernel/dir.c b/src/kernel/dir.c index 0795afda8ba53..8df659395d14e 100644 --- a/src/kernel/dir.c +++ b/src/kernel/dir.c @@ -9,6 +9,7 @@ const struct file_operations ceph_dir_fops; /* * build a dentry's path, relative to sb root. allocate on * heap; caller must kfree. + * (based on build_path_from_dentry in fs/cifs/dir.c) */ char *ceph_build_dentry_path(struct dentry *dentry, int *plen) { @@ -29,7 +30,7 @@ retry: return ERR_PTR(-EINVAL); } } - if (len) len--; + if (len) len--; /* no leading '/' */ path = kmalloc(len+1, GFP_KERNEL); if (path == NULL) @@ -55,7 +56,7 @@ 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) */ @@ -352,6 +353,102 @@ static int ceph_fill_trace(struct super_block *sb, struct ceph_mds_reply_info *p return err; } +static int ceph_dir_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) +{ + struct ceph_super_info *sbinfo = ceph_sbinfo(dir->i_sb); + struct ceph_mds_client *mdsc = &sbinfo->sb_client->mdsc; + struct inode *inode = NULL; + struct ceph_msg *req; + struct ceph_mds_request_head *rhead; + struct ceph_mds_reply_info rinfo; + char *path; + int pathlen; + int err; + + dout(5, "dir_mknod 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, + dir->i_sb->s_root->d_inode->i_ino, path, 0, 0); + kfree(path); + if (IS_ERR(req)) { + d_drop(dentry); + return PTR_ERR(req); + } + 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, -1)) < 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); + + if (err < 0) { + goto done; + } + + if (inode == NULL) { + /* TODO handle this one */ + err = -ENOMEM; + goto done; + } + dout(10, "rinfo.dir_in=%p rinfo.trace_nr=%d\n", rinfo.trace_in, rinfo.trace_nr); + } +done: + return err; +} + +static int ceph_dir_symlink(struct inode *dir, struct dentry *dentry, const char *dest) +{ + struct ceph_super_info *sbinfo = ceph_sbinfo(dir->i_sb); + struct ceph_mds_client *mdsc = &sbinfo->sb_client->mdsc; + struct inode *inode = NULL; + struct ceph_msg *req; + struct ceph_mds_reply_info rinfo; + char *path; + int pathlen; + int err; + + dout(5, "dir_symlink 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, + dir->i_sb->s_root->d_inode->i_ino, 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, -1)) < 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); + + if (err < 0) { + goto done; + } + + if (inode == NULL) { + /* TODO handle this one */ + err = -ENOMEM; + goto done; + } + dout(10, "rinfo.dir_in=%p rinfo.trace_nr=%d\n", rinfo.trace_in, rinfo.trace_nr); + } +done: + return err; +} + static int ceph_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode) { struct ceph_super_info *sbinfo = ceph_sbinfo(dir->i_sb); @@ -490,6 +587,8 @@ ceph_dir_create(struct inode *dir, struct dentry *dentry, int mode, const struct inode_operations ceph_dir_iops = { .lookup = ceph_dir_lookup, // .getattr = ceph_inode_getattr, + .mknod = ceph_dir_mknod, + .symlink = ceph_dir_symlink, .mkdir = ceph_dir_mkdir, .unlink = ceph_dir_unlink, .rmdir = ceph_dir_unlink, diff --git a/src/kernel/inode.c b/src/kernel/inode.c index 9a4b8cb90034c..4df6a753b4e09 100644 --- a/src/kernel/inode.c +++ b/src/kernel/inode.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include @@ -16,6 +18,7 @@ int ceph_fill_inode(struct inode *inode, struct ceph_mds_reply_inode *info) { struct ceph_inode_info *ci = ceph_inode(inode); int i; + int symlen; inode->i_ino = le64_to_cpu(info->ino); inode->i_mode = le32_to_cpu(info->mode); @@ -25,7 +28,6 @@ int ceph_fill_inode(struct inode *inode, struct ceph_mds_reply_inode *info) inode->i_size = le64_to_cpu(info->size); inode->i_rdev = le32_to_cpu(info->rdev); inode->i_blocks = 1; - inode->i_rdev = 0; insert_inode_hash(inode); @@ -41,6 +43,10 @@ int ceph_fill_inode(struct inode *inode, struct ceph_mds_reply_inode *info) ci->i_layout = info->layout; dout(30, "inode layout %p su %d\n", &ci->i_layout, ci->i_layout.fl_stripe_unit); + if (ci->i_symlink) + kfree(ci->i_symlink); + ci->i_symlink = 0; + if (le32_to_cpu(info->fragtree.nsplits) > 0) { //ci->i_fragtree = kmalloc(...); BUG_ON(1); // write me @@ -80,6 +86,17 @@ int ceph_fill_inode(struct inode *inode, struct ceph_mds_reply_inode *info) case S_IFLNK: dout(20, "%p is a symlink\n", inode); inode->i_op = &ceph_symlink_iops; + symlen = le32_to_cpu(*(__u32*)(info->fragtree.splits+ci->i_fragtree->nsplits)); + dout(20, "symlink len is %d\n", symlen); + BUG_ON(symlen != ci->vfs_inode.i_size); + ci->i_symlink = kmalloc(symlen+1, GFP_KERNEL); + if (ci->i_symlink == NULL) + return -ENOMEM; + memcpy(ci->i_symlink, + (char*)(info->fragtree.splits+ci->i_fragtree->nsplits) + 4, + symlen); + ci->i_symlink[symlen] = 0; + dout(20, "symlink is '%s'\n", ci->i_symlink); break; case S_IFDIR: dout(20, "%p is a dir\n", inode); @@ -236,46 +253,20 @@ int ceph_inode_getattr(struct vfsmount *mnt, struct dentry *dentry, /* + * symlinks + */ - -static int ceph_vfs_setattr(struct dentry *dentry, struct iattr *iattr) -{ -} - -static int ceph_vfs_readlink(struct dentry *dentry, char __user * buffer, - int buflen) -{ -} - -static void *ceph_vfs_follow_link(struct dentry *dentry, struct nameidata *nd) -{ -} - -static void ceph_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p) -{ -} - -static int -ceph_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) -{ -} - -static int -ceph_vfs_link(struct dentry *old_dentry, struct inode *dir, - struct dentry *dentry) -{ -} - -static int -ceph_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) +static void * ceph_sym_follow_link(struct dentry *dentry, struct nameidata *nd) { + struct ceph_inode_info *ci = ceph_inode(dentry->d_inode); + nd_set_link(nd, ci->i_symlink); + return NULL; } -*/ const struct inode_operations ceph_symlink_iops = { -/* .readlink = ceph_vfs_readlink, - .follow_link = ceph_vfs_follow_link, - .put_link = ceph_vfs_put_link, + .readlink = generic_readlink, + .follow_link = ceph_sym_follow_link, +/* .put_link = ceph_vfs_put_link, .getattr = ceph_vfs_getattr, .setattr = ceph_vfs_setattr, */ diff --git a/src/kernel/super.c b/src/kernel/super.c index bdc3a9fe9e5ca..655f38bad6089 100644 --- a/src/kernel/super.c +++ b/src/kernel/super.c @@ -113,6 +113,8 @@ static struct inode *ceph_alloc_inode(struct super_block *sb) if (!ci) return NULL; + ci->i_symlink = 0; + ci->i_fragtree = ci->i_fragtree_static; ci->i_fragtree->nsplits = 0; @@ -130,9 +132,11 @@ static struct inode *ceph_alloc_inode(struct super_block *sb) static void ceph_destroy_inode(struct inode *inode) { struct ceph_inode_info *ci = ceph_inode(inode); - + if (ci->i_caps != ci->i_caps_static) kfree(ci->i_caps); + if (ci->i_symlink) + kfree(ci->i_symlink); kmem_cache_free(ceph_inode_cachep, ci); } diff --git a/src/kernel/super.h b/src/kernel/super.h index 524bab44c09e0..9f2981e796fa0 100644 --- a/src/kernel/super.h +++ b/src/kernel/super.h @@ -80,6 +80,8 @@ enum { struct ceph_inode_info { struct ceph_file_layout i_layout; + char *i_symlink; + 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]; diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index 4320750c50eb8..aa57b3a582bde 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -59,7 +59,7 @@ ostream& operator<<(ostream& out, CInode& in) assert(in.get_replica_nonce() >= 0); } - if (in.is_symlink()) out << " symlink"; + if (in.is_symlink()) out << " symlink='" << in.symlink << "'"; if (in.is_dir() && !in.dirfragtree.empty()) out << " " << in.dirfragtree; out << " v" << in.get_version(); diff --git a/src/mds/Server.cc b/src/mds/Server.cc index bba24bf526d2a..f27c30412113a 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -1709,10 +1709,10 @@ void Server::handle_client_mknod(MDRequest *mdr) // it's a file. newi->inode.rdev = req->head.args.mknod.rdev; newi->inode.mode = req->head.args.mknod.mode; - newi->inode.mode &= ~S_IFMT; - newi->inode.mode |= S_IFREG; newi->inode.version = dn->pre_dirty() - 1; + dout(10) << "mknod mode " << newi->inode.mode << " rdev " << newi->inode.rdev << dendl; + // prepare finisher mdr->ls = mdlog->get_current_segment(); EUpdate *le = new EUpdate(mdlog, "mknod"); @@ -1802,7 +1802,9 @@ void Server::handle_client_symlink(MDRequest *mdr) // it's a symlink newi->inode.mode &= ~S_IFMT; newi->inode.mode |= S_IFLNK; + newi->inode.mode |= 0777; // ? newi->symlink = req->get_path2(); + newi->inode.size = newi->symlink.length(); newi->inode.version = dn->pre_dirty() - 1; // prepare finisher diff --git a/src/messages/MClientRequest.h b/src/messages/MClientRequest.h index 5db05daffc561..7ba2df108a926 100644 --- a/src/messages/MClientRequest.h +++ b/src/messages/MClientRequest.h @@ -185,7 +185,7 @@ public: const string& get_path() { return path.get_path(); } filepath& get_filepath() { return path; } - const string& get_path2() { return path.get_path(); } + const string& get_path2() { return path2.get_path(); } filepath& get_filepath2() { return path2; } inodeno_t get_mds_wants_replica_in_dirino() { -- 2.39.5