From: jcl Date: Thu, 9 Aug 2012 21:29:05 +0000 (+0200) Subject: LU-1729: lu_buf code cleaning X-Git-Tag: 2.3.55~34 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=0ddcb9b4671365d6cfd2d5ef2b4dd3f78d2610bb;hp=d3972843ae3ba829f821bd135d5ba97d4b0356f3 LU-1729: lu_buf code cleaning Fix DLUBUF define and use LU_BUF_NULL to clear a lu_buf Change-Id: I742308616d9c39196e56bf4983523152d26e1245 Signed-off-by: jcl Reviewed-on: http://review.whamcloud.com/3589 Reviewed-by: Bob Glossman Tested-by: Hudson Tested-by: Maloo Reviewed-by: Keith Mannthey Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h index 0d816d2..175de05 100644 --- a/lustre/include/lu_object.h +++ b/lustre/include/lu_object.h @@ -1306,7 +1306,7 @@ struct lu_buf { /** null buffer */ extern struct lu_buf LU_BUF_NULL; -#define DLUBUF "(%p %z)" +#define DLUBUF "(%p %zu)" #define PLUBUF(buf) (buf)->lb_buf, (buf)->lb_len /** * One-time initializers, called at obdclass module initialization, not diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index 2851a70..e1b75af 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -119,11 +119,10 @@ struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len) void mdd_buf_put(struct lu_buf *buf) { - if (buf == NULL || buf->lb_buf == NULL) - return; - OBD_FREE_LARGE(buf->lb_buf, buf->lb_len); - buf->lb_buf = NULL; - buf->lb_len = 0; + if (buf == NULL || buf->lb_buf == NULL) + return; + OBD_FREE_LARGE(buf->lb_buf, buf->lb_len); + *buf = LU_BUF_NULL; } const struct lu_buf *mdd_buf_get_const(const struct lu_env *env, @@ -139,19 +138,19 @@ const struct lu_buf *mdd_buf_get_const(const struct lu_env *env, struct lu_buf *mdd_buf_alloc(const struct lu_env *env, ssize_t len) { - struct lu_buf *buf = &mdd_env_info(env)->mti_big_buf; + struct lu_buf *buf = &mdd_env_info(env)->mti_big_buf; - if ((len > buf->lb_len) && (buf->lb_buf != NULL)) { - OBD_FREE_LARGE(buf->lb_buf, buf->lb_len); - buf->lb_buf = NULL; - } - if (buf->lb_buf == NULL) { - buf->lb_len = len; - OBD_ALLOC_LARGE(buf->lb_buf, buf->lb_len); - if (buf->lb_buf == NULL) - buf->lb_len = 0; - } - return buf; + if ((len > buf->lb_len) && (buf->lb_buf != NULL)) { + OBD_FREE_LARGE(buf->lb_buf, buf->lb_len); + *buf = LU_BUF_NULL; + } + if (memcmp(buf, &LU_BUF_NULL, sizeof(*buf)) == 0) { + buf->lb_len = len; + OBD_ALLOC_LARGE(buf->lb_buf, buf->lb_len); + if (buf->lb_buf == NULL) + *buf = LU_BUF_NULL; + } + return buf; } /** Increase the size of the \a mti_big_buf.