Skip to content

Commit

Permalink
Merge pull request #6649 from majianpeng/filesstore-lfnunlink
Browse files Browse the repository at this point in the history
osd: FileStore:: optimize lfn_unlink

Reviewed-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
liewegas committed Jan 1, 2016
2 parents 68a7c04 + 3ee2f6d commit 2694e11
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/os/CollectionIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class CollectionIndex {
virtual int lookup(
const ghobject_t &oid, ///< [in] Object to lookup
IndexedPath *path, ///< [out] Path to object
int *exist ///< [out] True if the object exists, else false
int *hardlink ///< [out] number of hard links of this object. *hardlink=0 mean object no-exist.
) = 0;

/**
Expand Down
20 changes: 6 additions & 14 deletions src/os/FileStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -457,28 +457,20 @@ int FileStore::lfn_unlink(coll_t cid, const ghobject_t& o,

{
IndexedPath path;
int exist;
r = index->lookup(o, &path, &exist);
int hardlink;
r = index->lookup(o, &path, &hardlink);
if (r < 0) {
assert(!m_filestore_fail_eio || r != -EIO);
return r;
}

if (!force_clear_omap) {
struct stat st;
r = ::stat(path->path(), &st);
if (r < 0) {
r = -errno;
if (r == -ENOENT) {
if (hardlink == 0) {
wbthrottle.clear_object(o); // should be only non-cache ref
fdcache.clear(o);
} else {
assert(!m_filestore_fail_eio || r != -EIO);
}
dout(25) << __func__ << " stat failed " << cpp_strerror(r) << dendl;
return r;
} else if (st.st_nlink == 1) {
force_clear_omap = true;
return 0;
} else if (hardlink == 1) {
force_clear_omap = true;
}
}
if (force_clear_omap) {
Expand Down
4 changes: 2 additions & 2 deletions src/os/HashIndex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ int HashIndex::_remove(const vector<string> &path,
int HashIndex::_lookup(const ghobject_t &oid,
vector<string> *path,
string *mangled_name,
int *exists_out) {
int *hardlink) {
vector<string> path_comp;
get_path_components(oid, &path_comp);
vector<string>::iterator next = path_comp.begin();
Expand All @@ -380,7 +380,7 @@ int HashIndex::_lookup(const ghobject_t &oid,
break;
path->push_back(*(next++));
}
return get_mangled_name(*path, oid, mangled_name, exists_out);
return get_mangled_name(*path, oid, mangled_name, hardlink);
}

int HashIndex::_collection_list_partial(const ghobject_t &start,
Expand Down
2 changes: 1 addition & 1 deletion src/os/HashIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class HashIndex : public LFNIndex {
const ghobject_t &oid,
vector<string> *path,
string *mangled_name,
int *exists
int *hardlink
);

/**
Expand Down
47 changes: 19 additions & 28 deletions src/os/LFNIndex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,29 +115,15 @@ int LFNIndex::unlink(const ghobject_t &oid)

int LFNIndex::lookup(const ghobject_t &oid,
IndexedPath *out_path,
int *exist)
int *hardlink)
{
WRAP_RETRY(
vector<string> path;
string short_name;
r = _lookup(oid, &path, &short_name, exist);
r = _lookup(oid, &path, &short_name, hardlink);
if (r < 0)
goto out;
string full_path = get_full_path(path, short_name);
struct stat buf;
maybe_inject_failure();
r = ::stat(full_path.c_str(), &buf);
maybe_inject_failure();
if (r < 0) {
if (errno == ENOENT) {
*exist = 0;
} else {
r = -errno;
goto out;
}
} else {
*exist = 1;
}
*out_path = IndexedPath(new Path(full_path, this));
r = 0;
);
Expand Down Expand Up @@ -313,14 +299,16 @@ int LFNIndex::remove_object(const vector<string> &from,
maybe_inject_failure();
if (r < 0)
return r;
if (exist == 0)
return -ENOENT;
return lfn_unlink(from, oid, short_name);
}

int LFNIndex::get_mangled_name(const vector<string> &from,
const ghobject_t &oid,
string *mangled_name, int *exists)
string *mangled_name, int *hardlink)
{
return lfn_get_name(from, oid, mangled_name, 0, exists);
return lfn_get_name(from, oid, mangled_name, 0, hardlink);
}

int LFNIndex::move_subdir(
Expand Down Expand Up @@ -724,7 +712,7 @@ string LFNIndex::lfn_generate_object_name_poolless(const ghobject_t &oid)
int LFNIndex::lfn_get_name(const vector<string> &path,
const ghobject_t &oid,
string *mangled_name, string *out_path,
int *exists)
int *hardlink)
{
string subdir_path = get_full_path_subdir(path);
string full_name = lfn_generate_object_name(oid);
Expand All @@ -735,18 +723,18 @@ int LFNIndex::lfn_get_name(const vector<string> &path,
*mangled_name = full_name;
if (out_path)
*out_path = get_full_path(path, full_name);
if (exists) {
if (hardlink) {
struct stat buf;
string full_path = get_full_path(path, full_name);
maybe_inject_failure();
r = ::stat(full_path.c_str(), &buf);
if (r < 0) {
if (errno == ENOENT)
*exists = 0;
*hardlink = 0;
else
return -errno;
} else {
*exists = 1;
*hardlink = buf.st_nlink;
}
}
return 0;
Expand Down Expand Up @@ -776,8 +764,8 @@ int LFNIndex::lfn_get_name(const vector<string> &path,
*mangled_name = candidate;
if (out_path)
*out_path = candidate_path;
if (exists)
*exists = 0;
if (hardlink)
*hardlink = 0;
return 0;
}
assert(r > 0);
Expand All @@ -787,8 +775,11 @@ int LFNIndex::lfn_get_name(const vector<string> &path,
*mangled_name = candidate;
if (out_path)
*out_path = candidate_path;
if (exists)
*exists = 1;
if (hardlink) {
struct stat st;
r = ::stat(candidate_path.c_str(), &st);
*hardlink = st.st_nlink;
}
return 0;
}
r = chain_getxattr(candidate_path.c_str(), get_alt_lfn_attr().c_str(),
Expand Down Expand Up @@ -818,8 +809,8 @@ int LFNIndex::lfn_get_name(const vector<string> &path,
*mangled_name = candidate;
if (out_path)
*out_path = candidate_path;
if (exists)
*exists = 1;
if (hardlink)
*hardlink = st.st_nlink;
return 0;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/os/LFNIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class LFNIndex : public CollectionIndex {
int lookup(
const ghobject_t &oid,
IndexedPath *path,
int *exist
int *hardlink
);

/// @see CollectionIndex;
Expand Down Expand Up @@ -326,7 +326,7 @@ class LFNIndex : public CollectionIndex {
const vector<string> &from, ///< [in] Subdirectory
const ghobject_t &oid, ///< [in] Object
string *mangled_name, ///< [out] Filename
int *exists ///< [out] 1 if the file exists, else 0
int *hardlink ///< [out] hardlink for this file, hardlink=0 mean no-exist
);

/// do move subdir from from to dest
Expand Down Expand Up @@ -424,7 +424,7 @@ class LFNIndex : public CollectionIndex {
* @param [in] oid Object for which to get filename.
* @param [out] mangled_name Filename for oid, pass NULL if not needed.
* @param [out] full_path Fullpath for oid, pass NULL if not needed.
* @param [out] exists 1 if the file exists, 0 otherwise, pass NULL if
* @param [out] hardlink of this file, 0 mean no-exist, pass NULL if
* not needed
* @return Error Code, 0 on success.
*/
Expand All @@ -433,7 +433,7 @@ class LFNIndex : public CollectionIndex {
const ghobject_t &oid,
string *mangled_name,
string *full_path,
int *exists
int *hardlink
);

/// Adjusts path contents when oid is created at name mangled_name.
Expand Down

0 comments on commit 2694e11

Please sign in to comment.