[sheepdog] [PATCH] Sheepdog, store: Update the get_store_temp_path function
Hitoshi Mitake
mitake.hitoshi at gmail.com
Thu Jul 9 16:35:19 CEST 2015
At Thu, 09 Jul 2015 13:58:59 +0800,
Ziye Yang wrote:
>
> This function is nearly same with get_store_path, the
> only difference is to add ".tmp" of the return string.
> It can be optimized to reduce the duplicated code.
>
> Signed-off-by: Ziye Yang <ziye.yang at intel.com>
> ---
> sheep/store/plain_store.c | 12 ++++--------
> sheep/store/tree_store.c | 22 ++++------------------
> 2 files changed, 8 insertions(+), 26 deletions(-)
Applied, thanks.
Hitoshi
>
> diff --git a/sheep/store/plain_store.c b/sheep/store/plain_store.c
> index db1a32c..2cc9479 100644
> --- a/sheep/store/plain_store.c
> +++ b/sheep/store/plain_store.c
> @@ -28,15 +28,11 @@ static int get_store_path(uint64_t oid, uint8_t ec_index, char *path)
>
> static int get_store_tmp_path(uint64_t oid, uint8_t ec_index, char *path)
> {
> - if (is_erasure_oid(oid)) {
> - if (unlikely(ec_index >= SD_MAX_COPIES))
> - panic("invalid ec_index %d", ec_index);
> - return snprintf(path, PATH_MAX, "%s/%016"PRIx64"_%d.tmp",
> - md_get_object_dir(oid), oid, ec_index);
> - }
> + char tmp_path[PATH_MAX];
>
> - return snprintf(path, PATH_MAX, "%s/%016" PRIx64".tmp",
> - md_get_object_dir(oid), oid);
> + get_store_path(oid, ec_index, path);
> + memcpy(tmp_path, path, PATH_MAX);
> + return snprintf(path, PATH_MAX, "%s.tmp", tmp_path);
> }
>
> static int get_store_stale_path(uint64_t oid, uint32_t epoch, uint8_t ec_index,
> diff --git a/sheep/store/tree_store.c b/sheep/store/tree_store.c
> index b7fd8a5..31217e7 100644
> --- a/sheep/store/tree_store.c
> +++ b/sheep/store/tree_store.c
> @@ -43,25 +43,11 @@ static int get_store_path(uint64_t oid, uint8_t ec_index, char *path)
>
> static int get_store_tmp_path(uint64_t oid, uint8_t ec_index, char *path)
> {
> - char tree_path[PATH_MAX];
> -
> - if (is_vdi_obj(oid) || is_vmstate_obj(oid) || is_vdi_attr_obj(oid)) {
> - snprintf(tree_path, PATH_MAX, "%s/meta",
> - md_get_object_dir(oid));
> - } else {
> - snprintf(tree_path, PATH_MAX, "%s/%02x",
> - md_get_object_dir(oid), get_tree_directory(oid));
> - }
> -
> - if (is_erasure_oid(oid)) {
> - if (unlikely(ec_index >= SD_MAX_COPIES))
> - panic("invalid ec_index %d", ec_index);
> - return snprintf(path, PATH_MAX, "%s/%016"PRIx64"_%d.tmp",
> - tree_path, oid, ec_index);
> - }
> + char tmp_path[PATH_MAX];
>
> - return snprintf(path, PATH_MAX, "%s/%016" PRIx64".tmp",
> - tree_path, oid);
> + get_store_path(oid, ec_index, path);
> + memcpy(tmp_path, path, PATH_MAX);
> + return snprintf(path, PATH_MAX, "%s.tmp", tmp_path);
> }
>
> static int get_store_stale_path(uint64_t oid, uint32_t epoch, uint8_t ec_index,
>
> --
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> https://lists.wpkg.org/mailman/listinfo/sheepdog
More information about the sheepdog
mailing list