diff --git a/fs/hmdfs/file_merge.c b/fs/hmdfs/file_merge.c index ca83a04a92a15c4a68fe7af11721a039d0f28db5..fa334915a8e2425c9af370422c60cad20142562d 100644 --- a/fs/hmdfs/file_merge.c +++ b/fs/hmdfs/file_merge.c @@ -386,7 +386,7 @@ int do_dir_open_merge(struct file *file, const struct cred *cred, if (IS_ERR_OR_NULL(cred)) return ret; - + wait_event(dim->wait_queue, !has_merge_lookup_work(dim)); mutex_lock(&dim->comrade_list_lock); @@ -601,39 +601,48 @@ static int copy_string_from_user(unsigned long pos, unsigned long len, { char *tmp_data; - if (!access_ok((char *)pos, len)) + if (!access_ok(pos, len)) { + hmdfs_err("User space pointer is not available, %d", EFAULT); return -EFAULT; + } tmp_data = kmalloc(len, GFP_KERNEL); - if (!tmp_data) + if (!tmp_data) { + hmdfs_err("No Memory, %d", ENOMEM); return -ENOMEM; + } *data = tmp_data; - if (copy_from_user(tmp_data, (char __user *)pos, len)){ + if (copy_from_user(tmp_data, (char __user *)pos, len)) { + hmdfs_err("Data is not fully copied, %d", EFAULT); return -EFAULT; } return 0; } -static int hmdfs_get_info_from_user(unsigned long pos, +static int hmdfs_get_info_from_user(unsigned long pos, struct hmdfs_dst_info *hdi, struct hmdfs_user_info *data) { int ret = 0; - if (!access_ok((struct hmdfs_dst_info __user *)pos, - sizeof(struct hmdfs_dst_info))) - return -ENOMEM; + if (!access_ok((struct hmdfs_dst_info __user *)pos, + sizeof(struct hmdfs_dst_info))) { + hmdfs_err("User space pointer of struct is not available, %d", EFAULT); + return -EFAULT; + } if (copy_from_user(hdi, (struct hmdfs_dst_info __user *)pos, - sizeof(struct hmdfs_dst_info))) + sizeof(struct hmdfs_dst_info))) { + hmdfs_err("Struct is not fully copied, %d", EFAULT); return -EFAULT; - + } + ret = copy_string_from_user(hdi->local_path_pos, hdi->local_path_len, &data->local_path); if (ret != 0) return ret; - ret = copy_string_from_user(hdi->distributed_path_pos, + ret = copy_string_from_user(hdi->distributed_path_pos, hdi->distributed_path_len, &data->distributed_path); if (ret != 0) @@ -647,7 +656,7 @@ static int hmdfs_get_info_from_user(unsigned long pos, return 0; } -static const struct cred *change_cred(struct dentry *dentry, +static const struct cred *change_cred(struct dentry *dentry, const char *bundle_name) { int bid; @@ -656,6 +665,7 @@ static const struct cred *change_cred(struct dentry *dentry, cred = prepare_creds(); if (!cred) { + hmdfs_err("Failed to prepare cred, %d", EACCES); return NULL; } bid = get_bundle_uid(hmdfs_sb(dentry->d_sb), bundle_name); @@ -664,7 +674,7 @@ static const struct cred *change_cred(struct dentry *dentry, cred->fsgid = KGIDT_INIT(bid); old_cred = override_creds(cred); } - + return old_cred; } @@ -701,10 +711,12 @@ static int create_link_file(struct hmdfs_user_info *data) path_put(&path); return ret; } - + dentry = kern_path_create(AT_FDCWD, data->distributed_path, &path, 0); - if (IS_ERR(dentry)) + if (IS_ERR(dentry)) { + hmdfs_err("create_link_file failed, %ld", PTR_ERR(dentry)); return PTR_ERR(dentry); + } ret = vfs_symlink(path.dentry->d_inode, dentry, data->local_path); done_path_create(&path, dentry); @@ -720,14 +732,16 @@ static int create_dir(const char *path_value, mode_t mode) dentry = kern_path_create(AT_FDCWD, path_value, &path, LOOKUP_DIRECTORY); if(PTR_ERR(dentry) == -EEXIST) return 0; - if (IS_ERR(dentry)) + if (IS_ERR(dentry)) { + hmdfs_err("create_dir failed, %ld", PTR_ERR(dentry)); return PTR_ERR(dentry); + } err = vfs_mkdir(d_inode(path.dentry), dentry, mode); if (err && err != -EEXIST) hmdfs_err("vfs_mkdir failed, err = %d", err); done_path_create(&path, dentry); - + return err; } diff --git a/fs/hmdfs/hmdfs_server.c b/fs/hmdfs/hmdfs_server.c index d2dec5c95ccb9abd85bc0685e419cbcee81200b7..2e7a0cbaf250d695778d58fb9396add03a5467e8 100644 --- a/fs/hmdfs/hmdfs_server.c +++ b/fs/hmdfs/hmdfs_server.c @@ -98,7 +98,7 @@ struct file *hmdfs_open_link(struct hmdfs_sb_info *sbi, if (IS_ERR(file)) { hmdfs_info("filp_open failed: %ld", PTR_ERR(file)); } else { - hmdfs_info("get file with magic %lu", + hmdfs_info("get file with magic %lu", file->f_inode->i_sb->s_magic); } @@ -190,7 +190,7 @@ void __init hmdfs_server_add_node_evt_cb(void) hmdfs_node_add_evt_cb(server_cb, ARRAY_SIZE(server_cb)); } -static int hmdfs_get_inode_by_name(struct hmdfs_peer *con, const char *filename, +static int hmdfs_get_inode_by_name(struct hmdfs_peer *con, const char *filename, uint64_t *ino) { int ret = 0; @@ -204,7 +204,7 @@ static int hmdfs_get_inode_by_name(struct hmdfs_peer *con, const char *filename, return ret; } - ret = vfs_path_lookup(root_path.dentry, root_path.mnt, filename, 0, + ret = vfs_path_lookup(root_path.dentry, root_path.mnt, filename, 0, &dst_path); if (ret) { path_put(&root_path); @@ -1224,7 +1224,7 @@ void hmdfs_server_rename(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, hmdfs_send_err_response(con, cmd, err); } -static int hmdfs_lookup_symlink(struct path *link_path, const char *path_fmt, +static int hmdfs_lookup_symlink(struct path *link_path, const char *path_fmt, ... ) { int ret; @@ -1233,7 +1233,7 @@ static int hmdfs_lookup_symlink(struct path *link_path, const char *path_fmt, if (!path) return -ENOMEM; - + va_start(args, path_fmt); ret = vsnprintf(path, PATH_MAX, path_fmt, args); va_end(args); @@ -1311,11 +1311,11 @@ static int hmdfs_filldir_real(struct dir_context *ctx, const char *name, } else if (d_type == DT_LNK) { struct path link_path; - res = hmdfs_lookup_symlink(&link_path, "%s/%s/%s", + res = hmdfs_lookup_symlink(&link_path, "%s/%s/%s", gc->sbi->local_src, gc->dir, name); if (!res) { - create_dentry(child, d_inode(link_path.dentry), + create_dentry(child, d_inode(link_path.dentry), gc->file, gc->sbi); path_put(&link_path); gc->num++; @@ -1448,17 +1448,17 @@ void hmdfs_server_writepage(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, hmdfs_server_check_writeback(hswb); } -static int hmdfs_lookup_linkpath(struct hmdfs_sb_info *sbi, +static int hmdfs_lookup_linkpath(struct hmdfs_sb_info *sbi, const char *path_name, struct path *dst_path) { struct path link_path; int err; - err = hmdfs_lookup_symlink(&link_path, "%s/%s", sbi->local_dst, + err = hmdfs_lookup_symlink(&link_path, "%s/%s", sbi->local_dst, path_name); if (err) return err; - + if (d_inode(link_path.dentry)->i_sb != sbi->sb) { path_put(dst_path); *dst_path = link_path; @@ -1537,7 +1537,7 @@ void hmdfs_server_setattr(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, if (S_ISLNK(inode->i_mode)) { err = hmdfs_lookup_linkpath(con->sbi, recv->buf, &dst_path); - if(err == -ENOENT) + if(err == -ENOENT) err = 0; else if (err) goto out_put_dst; @@ -1634,7 +1634,7 @@ void hmdfs_server_getattr(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, if (S_ISLNK(inode->i_mode)) { err = hmdfs_lookup_linkpath(con->sbi, recv->buf, &dst_path); - if(err && err != -ENOENT) + if(err && err != -ENOENT) goto out_put_dst; } diff --git a/fs/hmdfs/inode_local.c b/fs/hmdfs/inode_local.c index aca355d33928393addcd9baca7810f923ad496be..55f56d35f4b38b52f04824012ac5a1f802e35b30 100644 --- a/fs/hmdfs/inode_local.c +++ b/fs/hmdfs/inode_local.c @@ -740,8 +740,8 @@ int hmdfs_rename_local(struct inode *old_dir, struct dentry *old_dentry, return err; } -static const char *hmdfs_get_link_local(struct dentry *dentry, - struct inode *inode, +static const char *hmdfs_get_link_local(struct dentry *dentry, + struct inode *inode, struct delayed_call *done) { const char *link = NULL; diff --git a/fs/hmdfs/inode_merge.c b/fs/hmdfs/inode_merge.c index 1982f446ff3111c0580ac2b797165f9e8d7102b1..c0bebf3a1fc0604bf675069bcc2eec32cbade20f 100644 --- a/fs/hmdfs/inode_merge.c +++ b/fs/hmdfs/inode_merge.c @@ -850,8 +850,8 @@ int do_mkdir_merge(struct inode *parent_inode, struct dentry *child_dentry, ret = PTR_ERR(child_inode); goto out; } - child_inode->i_uid = parent_inode->i_uid; - child_inode->i_gid = parent_inode->i_gid; + check_and_fixup_ownership_remote(parent_inode, child_inode, + child_dentry); d_add(child_dentry, child_inode); /* nlink should be increased with the joining of children */ @@ -878,8 +878,8 @@ int do_create_merge(struct inode *parent_inode, struct dentry *child_dentry, ret = PTR_ERR(child_inode); goto out; } - child_inode->i_uid = parent_inode->i_uid; - child_inode->i_gid = parent_inode->i_gid; + check_and_fixup_ownership_remote(parent_inode, child_inode, + child_dentry); d_add(child_dentry, child_inode); /* nlink should be increased with the joining of children */ diff --git a/fs/hmdfs/inode_remote.c b/fs/hmdfs/inode_remote.c index fb227d41abb6700bf0f9ba23ed75b4ac1d3c3388..c42f81cb9a252382717229e1c5548831fde5b4c3 100644 --- a/fs/hmdfs/inode_remote.c +++ b/fs/hmdfs/inode_remote.c @@ -371,12 +371,15 @@ struct inode *fill_inode_remote(struct super_block *sb, struct hmdfs_peer *con, inode->i_uid = KUIDT_INIT((uid_t)1000); inode->i_gid = KGIDT_INIT((gid_t)1000); - if (S_ISDIR(mode)) + if (S_ISDIR(mode)) { inode->i_mode = S_IFDIR | S_IRWXU | S_IRWXG | S_IXOTH; - else if (S_ISREG(mode)) + } + else if (S_ISREG(mode)) { inode->i_mode = S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; - else if (S_ISLNK(mode)) + } + else if (S_ISLNK(mode)) { inode->i_mode = S_IFREG | S_IRWXU | S_IRWXG; + } else { ret = -EIO; goto bad_inode;