Skip to content

Commit

Permalink
lib, sheep: remove obsolete valloc() calls
Browse files Browse the repository at this point in the history
We should use posix_memalign() instead of valloc().

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
  • Loading branch information
mitake committed Jan 16, 2018
1 parent 65958e3 commit 5ebf14b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
7 changes: 4 additions & 3 deletions lib/util.c
Expand Up @@ -58,11 +58,12 @@ void *xcalloc(size_t nmemb, size_t size)
return ret;
}

/* zeroed memory version of valloc() */
/* zeroed memory version of posix_memalign() */
void *xvalloc(size_t size)
{
void *ret = valloc(size);
if (unlikely(!ret))
void *ret = NULL;
int err = posix_memalign((void **)&ret, getpagesize(), size);
if (unlikely(err))
panic("Out of memory");
memset(ret, 0, size);
return ret;
Expand Down
10 changes: 5 additions & 5 deletions sheep/gateway.c
Expand Up @@ -75,8 +75,8 @@ static void *init_erasure_buffer(struct request *req, int buf_len)
uint64_t tail = round_down(off + len, SD_EC_DATA_STRIPE_SIZE);
int ret;

buf = valloc(buf_len);
if(unlikely(!buf))
ret = posix_memalign((void **)&buf, getpagesize(), buf_len);
if(unlikely(ret))
return NULL;
memset(buf, 0, buf_len);

Expand Down Expand Up @@ -905,11 +905,11 @@ static int gateway_handle_cow(struct request *req)
uint64_t oid = req->rq.obj.oid;
size_t len = get_objsize(oid, get_vdi_object_size(oid_to_vid(oid)));
struct sd_req *req_hdr = &req->rq;
char *buf;
char *buf = NULL;
int ret;

buf = valloc(len);
if(unlikely(!buf)) {
ret = posix_memalign((void **)&buf, getpagesize(), len);
if(unlikely(ret)) {
ret = SD_RES_NO_MEM;
goto out;
}
Expand Down
6 changes: 4 additions & 2 deletions sheep/request.c
Expand Up @@ -660,9 +660,11 @@ struct request *alloc_request(struct client_info *ci, uint32_t data_length)
return NULL;

if (data_length) {
int ret;

req->data_length = data_length;
req->data = valloc(data_length);
if (!req->data) {
ret = posix_memalign((void **)&req->data, getpagesize(), data_length);
if (ret) {
free(req);
return NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions sheep/store/plain_store.c
Expand Up @@ -611,8 +611,8 @@ int default_get_hash(uint64_t oid, uint32_t epoch, uint8_t *sha1)
}

length = get_store_objsize(oid);
buf = valloc(length);
if (buf == NULL)
ret = posix_memalign((void **)&buf, getpagesize(), length);
if (ret)
return SD_RES_NO_MEM;

iocb.epoch = epoch;
Expand Down
6 changes: 3 additions & 3 deletions sheep/store/tree_store.c
Expand Up @@ -662,7 +662,7 @@ static int get_object_path(uint64_t oid, uint32_t epoch, char *path,
int tree_get_hash(uint64_t oid, uint32_t epoch, uint8_t *sha1)
{
int ret;
void *buf;
void *buf = NULL;
struct siocb iocb = {};
uint32_t length;
bool is_readonly_obj = oid_is_readonly(oid);
Expand All @@ -681,8 +681,8 @@ int tree_get_hash(uint64_t oid, uint32_t epoch, uint8_t *sha1)
}

length = get_store_objsize(oid);
buf = valloc(length);
if (buf == NULL)
ret = posix_memalign((void **)&buf, getpagesize(), length);
if (ret)
return SD_RES_NO_MEM;

iocb.epoch = epoch;
Expand Down

0 comments on commit 5ebf14b

Please sign in to comment.