Release 4.11 fs/btrfs/export.c
#include <linux/fs.h>
#include <linux/types.h>
#include "ctree.h"
#include "disk-io.h"
#include "btrfs_inode.h"
#include "print-tree.h"
#include "export.h"
#define BTRFS_FID_SIZE_NON_CONNECTABLE (offsetof(struct btrfs_fid, \
parent_objectid) / 4)
#define BTRFS_FID_SIZE_CONNECTABLE (offsetof(struct btrfs_fid, \
parent_root_objectid) / 4)
#define BTRFS_FID_SIZE_CONNECTABLE_ROOT (sizeof(struct btrfs_fid) / 4)
static int btrfs_encode_fh(struct inode *inode, u32 *fh, int *max_len,
struct inode *parent)
{
struct btrfs_fid *fid = (struct btrfs_fid *)fh;
int len = *max_len;
int type;
if (parent && (len < BTRFS_FID_SIZE_CONNECTABLE)) {
*max_len = BTRFS_FID_SIZE_CONNECTABLE;
return FILEID_INVALID;
} else if (len < BTRFS_FID_SIZE_NON_CONNECTABLE) {
*max_len = BTRFS_FID_SIZE_NON_CONNECTABLE;
return FILEID_INVALID;
}
len = BTRFS_FID_SIZE_NON_CONNECTABLE;
type = FILEID_BTRFS_WITHOUT_PARENT;
fid->objectid = btrfs_ino(BTRFS_I(inode));
fid->root_objectid = BTRFS_I(inode)->root->objectid;
fid->gen = inode->i_generation;
if (parent) {
u64 parent_root_id;
fid->parent_objectid = BTRFS_I(parent)->location.objectid;
fid->parent_gen = parent->i_generation;
parent_root_id = BTRFS_I(parent)->root->objectid;
if (parent_root_id != fid->root_objectid) {
fid->parent_root_objectid = parent_root_id;
len = BTRFS_FID_SIZE_CONNECTABLE_ROOT;
type = FILEID_BTRFS_WITH_PARENT_ROOT;
} else {
len = BTRFS_FID_SIZE_CONNECTABLE;
type = FILEID_BTRFS_WITH_PARENT;
}
}
*max_len = len;
return type;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Balaji Rao | 167 | 80.68% | 1 | 16.67% |
Aneesh Kumar K.V | 24 | 11.59% | 1 | 16.67% |
Al Viro | 8 | 3.86% | 1 | 16.67% |
Nikolay Borisov | 3 | 1.45% | 1 | 16.67% |
Li Zefan | 3 | 1.45% | 1 | 16.67% |
Namjae Jeon | 2 | 0.97% | 1 | 16.67% |
Total | 207 | 100.00% | 6 | 100.00% |
static struct dentry *btrfs_get_dentry(struct super_block *sb, u64 objectid,
u64 root_objectid, u32 generation,
int check_generation)
{
struct btrfs_fs_info *fs_info = btrfs_sb(sb);
struct btrfs_root *root;
struct inode *inode;
struct btrfs_key key;
int index;
int err = 0;
if (objectid < BTRFS_FIRST_FREE_OBJECTID)
return ERR_PTR(-ESTALE);
key.objectid = root_objectid;
key.type = BTRFS_ROOT_ITEM_KEY;
key.offset = (u64)-1;
index = srcu_read_lock(&fs_info->subvol_srcu);
root = btrfs_read_fs_root_no_name(fs_info, &key);
if (IS_ERR(root)) {
err = PTR_ERR(root);
goto fail;
}
key.objectid = objectid;
key.type = BTRFS_INODE_ITEM_KEY;
key.offset = 0;
inode = btrfs_iget(sb, &key, root, NULL);
if (IS_ERR(inode)) {
err = PTR_ERR(inode);
goto fail;
}
srcu_read_unlock(&fs_info->subvol_srcu, index);
if (check_generation && generation != inode->i_generation) {
iput(inode);
return ERR_PTR(-ESTALE);
}
return d_obtain_alias(inode);
fail:
srcu_read_unlock(&fs_info->subvol_srcu, index);
return ERR_PTR(err);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Balaji Rao | 102 | 42.50% | 1 | 16.67% |
Zheng Yan | 94 | 39.17% | 1 | 16.67% |
David Woodhouse | 35 | 14.58% | 1 | 16.67% |
David Sterba | 6 | 2.50% | 1 | 16.67% |
Josef Bacik | 2 | 0.83% | 1 | 16.67% |
Al Viro | 1 | 0.42% | 1 | 16.67% |
Total | 240 | 100.00% | 6 | 100.00% |
static struct dentry *btrfs_fh_to_parent(struct super_block *sb, struct fid *fh,
int fh_len, int fh_type)
{
struct btrfs_fid *fid = (struct btrfs_fid *) fh;
u64 objectid, root_objectid;
u32 generation;
if (fh_type == FILEID_BTRFS_WITH_PARENT) {
if (fh_len < BTRFS_FID_SIZE_CONNECTABLE)
return NULL;
root_objectid = fid->root_objectid;
} else if (fh_type == FILEID_BTRFS_WITH_PARENT_ROOT) {
if (fh_len < BTRFS_FID_SIZE_CONNECTABLE_ROOT)
return NULL;
root_objectid = fid->parent_root_objectid;
} else
return NULL;
objectid = fid->parent_objectid;
generation = fid->parent_gen;
return btrfs_get_dentry(sb, objectid, root_objectid, generation, 1);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Balaji Rao | 117 | 96.69% | 1 | 33.33% |
Zheng Yan | 2 | 1.65% | 1 | 33.33% |
Neil Brown | 2 | 1.65% | 1 | 33.33% |
Total | 121 | 100.00% | 3 | 100.00% |
static struct dentry *btrfs_fh_to_dentry(struct super_block *sb, struct fid *fh,
int fh_len, int fh_type)
{
struct btrfs_fid *fid = (struct btrfs_fid *) fh;
u64 objectid, root_objectid;
u32 generation;
if ((fh_type != FILEID_BTRFS_WITH_PARENT ||
fh_len < BTRFS_FID_SIZE_CONNECTABLE) &&
(fh_type != FILEID_BTRFS_WITH_PARENT_ROOT ||
fh_len < BTRFS_FID_SIZE_CONNECTABLE_ROOT) &&
(fh_type != FILEID_BTRFS_WITHOUT_PARENT ||
fh_len < BTRFS_FID_SIZE_NON_CONNECTABLE))
return NULL;
objectid = fid->objectid;
root_objectid = fid->root_objectid;
generation = fid->gen;
return btrfs_get_dentry(sb, objectid, root_objectid, generation, 1);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Balaji Rao | 106 | 95.50% | 1 | 33.33% |
Neil Brown | 3 | 2.70% | 1 | 33.33% |
Zheng Yan | 2 | 1.80% | 1 | 33.33% |
Total | 111 | 100.00% | 3 | 100.00% |
static struct dentry *btrfs_get_parent(struct dentry *child)
{
struct inode *dir = d_inode(child);
struct btrfs_fs_info *fs_info = btrfs_sb(dir->i_sb);
struct btrfs_root *root = BTRFS_I(dir)->root;
struct btrfs_path *path;
struct extent_buffer *leaf;
struct btrfs_root_ref *ref;
struct btrfs_key key;
struct btrfs_key found_key;
int ret;
path = btrfs_alloc_path();
if (!path)
return ERR_PTR(-ENOMEM);
if (btrfs_ino(BTRFS_I(dir)) == BTRFS_FIRST_FREE_OBJECTID) {
key.objectid = root->root_key.objectid;
key.type = BTRFS_ROOT_BACKREF_KEY;
key.offset = (u64)-1;
root = fs_info->tree_root;
} else {
key.objectid = btrfs_ino(BTRFS_I(dir));
key.type = BTRFS_INODE_REF_KEY;
key.offset = (u64)-1;
}
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0)
goto fail;
BUG_ON(ret == 0); /* Key with offset of -1 found */
if (path->slots[0] == 0) {
ret = -ENOENT;
goto fail;
}
path->slots[0]--;
leaf = path->nodes[0];
btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
if (found_key.objectid != key.objectid || found_key.type != key.type) {
ret = -ENOENT;
goto fail;
}
if (found_key.type == BTRFS_ROOT_BACKREF_KEY) {
ref = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_root_ref);
key.objectid = btrfs_root_ref_dirid(leaf, ref);
} else {
key.objectid = found_key.offset;
}
btrfs_free_path(path);
if (found_key.type == BTRFS_ROOT_BACKREF_KEY) {
return btrfs_get_dentry(fs_info->sb, key.objectid,
found_key.offset, 0, 0);
}
key.type = BTRFS_INODE_ITEM_KEY;
key.offset = 0;
return d_obtain_alias(btrfs_iget(fs_info->sb, &key, root, NULL));
fail:
btrfs_free_path(path);
return ERR_PTR(ret);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Zheng Yan | 192 | 46.83% | 1 | 7.14% |
Balaji Rao | 138 | 33.66% | 1 | 7.14% |
David Woodhouse | 35 | 8.54% | 3 | 21.43% |
Jeff Mahoney | 13 | 3.17% | 2 | 14.29% |
Liu Bo | 12 | 2.93% | 1 | 7.14% |
Nikolay Borisov | 6 | 1.46% | 1 | 7.14% |
Li Zefan | 6 | 1.46% | 1 | 7.14% |
David Howells | 3 | 0.73% | 1 | 7.14% |
Josef Bacik | 2 | 0.49% | 1 | 7.14% |
Christoph Hellwig | 2 | 0.49% | 1 | 7.14% |
Al Viro | 1 | 0.24% | 1 | 7.14% |
Total | 410 | 100.00% | 14 | 100.00% |
static int btrfs_get_name(struct dentry *parent, char *name,
struct dentry *child)
{
struct inode *inode = d_inode(child);
struct inode *dir = d_inode(parent);
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
struct btrfs_path *path;
struct btrfs_root *root = BTRFS_I(dir)->root;
struct btrfs_inode_ref *iref;
struct btrfs_root_ref *rref;
struct extent_buffer *leaf;
unsigned long name_ptr;
struct btrfs_key key;
int name_len;
int ret;
u64 ino;
if (!S_ISDIR(dir->i_mode))
return -EINVAL;
ino = btrfs_ino(BTRFS_I(inode));
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
path->leave_spinning = 1;
if (ino == BTRFS_FIRST_FREE_OBJECTID) {
key.objectid = BTRFS_I(inode)->root->root_key.objectid;
key.type = BTRFS_ROOT_BACKREF_KEY;
key.offset = (u64)-1;
root = fs_info->tree_root;
} else {
key.objectid = ino;
key.offset = btrfs_ino(BTRFS_I(dir));
key.type = BTRFS_INODE_REF_KEY;
}
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0) {
btrfs_free_path(path);
return ret;
} else if (ret > 0) {
if (ino == BTRFS_FIRST_FREE_OBJECTID) {
path->slots[0]--;
} else {
btrfs_free_path(path);
return -ENOENT;
}
}
leaf = path->nodes[0];
if (ino == BTRFS_FIRST_FREE_OBJECTID) {
rref = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_root_ref);
name_ptr = (unsigned long)(rref + 1);
name_len = btrfs_root_ref_name_len(leaf, rref);
} else {
iref = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_inode_ref);
name_ptr = (unsigned long)(iref + 1);
name_len = btrfs_inode_ref_name_len(leaf, iref);
}
read_extent_buffer(leaf, name, name_ptr, name_len);
btrfs_free_path(path);
/*
* have to add the null termination to make sure that reconnect_path
* gets the right len for strlen
*/
name[name_len] = '\0';
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Josef Bacik | 370 | 90.02% | 1 | 20.00% |
Li Zefan | 17 | 4.14% | 1 | 20.00% |
Jeff Mahoney | 12 | 2.92% | 1 | 20.00% |
Nikolay Borisov | 6 | 1.46% | 1 | 20.00% |
David Howells | 6 | 1.46% | 1 | 20.00% |
Total | 411 | 100.00% | 5 | 100.00% |
const struct export_operations btrfs_export_ops = {
.encode_fh = btrfs_encode_fh,
.fh_to_dentry = btrfs_fh_to_dentry,
.fh_to_parent = btrfs_fh_to_parent,
.get_parent = btrfs_get_parent,
.get_name = btrfs_get_name,
};
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Balaji Rao | 687 | 43.90% | 1 | 4.76% |
Josef Bacik | 379 | 24.22% | 2 | 9.52% |
Zheng Yan | 290 | 18.53% | 1 | 4.76% |
David Woodhouse | 70 | 4.47% | 3 | 14.29% |
Li Zefan | 26 | 1.66% | 1 | 4.76% |
Jeff Mahoney | 25 | 1.60% | 2 | 9.52% |
Aneesh Kumar K.V | 24 | 1.53% | 1 | 4.76% |
Nikolay Borisov | 15 | 0.96% | 1 | 4.76% |
Liu Bo | 12 | 0.77% | 1 | 4.76% |
Al Viro | 10 | 0.64% | 2 | 9.52% |
David Howells | 9 | 0.58% | 1 | 4.76% |
David Sterba | 6 | 0.38% | 1 | 4.76% |
Neil Brown | 5 | 0.32% | 1 | 4.76% |
Chris Mason | 3 | 0.19% | 1 | 4.76% |
Namjae Jeon | 2 | 0.13% | 1 | 4.76% |
Christoph Hellwig | 2 | 0.13% | 1 | 4.76% |
Total | 1565 | 100.00% | 21 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.