Whamcloud - gitweb
LU-1729: lu_buf code cleaning
authorjcl <jacques-charles.lafoucriere@cea.fr>
Thu, 9 Aug 2012 21:29:05 +0000 (23:29 +0200)
committerOleg Drokin <green@whamcloud.com>
Mon, 5 Nov 2012 22:22:40 +0000 (17:22 -0500)
Fix DLUBUF define and use LU_BUF_NULL to clear a lu_buf

Change-Id: I742308616d9c39196e56bf4983523152d26e1245
Signed-off-by: jcl <jacques-charles.lafoucriere@cea.fr>
Reviewed-on: http://review.whamcloud.com/3589
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Keith Mannthey <keith.mannthey@intel.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lu_object.h
lustre/mdd/mdd_object.c

index 0d816d2..175de05 100644 (file)
@@ -1306,7 +1306,7 @@ struct lu_buf {
 /** null buffer */
 extern struct lu_buf LU_BUF_NULL;
 
 /** 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
 #define PLUBUF(buf) (buf)->lb_buf, (buf)->lb_len
 /**
  * One-time initializers, called at obdclass module initialization, not
index 2851a70..e1b75af 100644 (file)
@@ -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)
 {
 
 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,
 }
 
 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 *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.
 }
 
 /** Increase the size of the \a mti_big_buf.