Whamcloud - gitweb
LU-1821 build: fix build error about VLA at file scope
authorPeng Tao <tao.peng@emc.com>
Tue, 28 Aug 2012 17:44:37 +0000 (01:44 +0800)
committerOleg Drokin <green@whamcloud.com>
Mon, 10 Sep 2012 15:33:08 +0000 (11:33 -0400)
Fix build error:
drivers/incore/fs_incore.c:340:54: error: variably modified
‘incore_dir_template’ at file scope [-Werror]

C99 does not allow VLA at file scope. Allocate incore_dir_template
dynamically to avoid build error with newer gcc(>4.6.3) that checks
this.

Signed-off-by: Peng Tao <tao.peng@emc.com>
Change-Id: Icc81c649f58772e76e1cd3dcd42348a53a9a942b
Reviewed-on: http://review.whamcloud.com/3856
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Yang Sheng <ys@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libsysio/drivers/incore/fs_incore.c
libsysio/include/fs.h
libsysio/src/init.c

index c2ce433..ec94abc 100644 (file)
@@ -336,8 +336,9 @@ struct lookup_data {
  * Given mode bits, return directory entry type code.
  */
 #define INCORE_D_TYPEOF(m)     (((m) & S_IFMT) >> 12)
+#define INCORE_D_TEMPLATE_LEN   (INCORE_D_RECLEN(1) + INCORE_D_RECLEN(2))
 
-static char incore_dir_template[INCORE_D_RECLEN(1) + INCORE_D_RECLEN(2)];
+char *incore_dir_template;
 #if 0
 static struct intnl_dirent incore_dir_template[] = {
        {
@@ -369,6 +370,9 @@ _sysio_incore_init()
        /*
         * Fill in the directory template.
         */
+       incore_dir_template = calloc(1, INCORE_D_TEMPLATE_LEN);
+       if (incore_dir_template == NULL)
+               return -ENOMEM;
        de = (struct intnl_dirent *)incore_dir_template;
 #ifdef _DIRENT_HAVE_D_OFF
        de->d_off =
@@ -489,14 +493,14 @@ incore_directory_new(struct incore_filesys *icfs,
        /*
         * Allocate and init directory data.
         */
-       err = incore_trunc(icino, sizeof(incore_dir_template), 1);
+       err = incore_trunc(icino, INCORE_D_TEMPLATE_LEN, 1);
        if (err) {
                incore_i_destroy(icino);
                return NULL;
        }
        (void )memcpy(icino->ici_data,
                      &incore_dir_template,
-                     sizeof(incore_dir_template));
+                     INCORE_D_TEMPLATE_LEN);
        de = icino->ici_data;
        de->d_ino = st->st_ino;
        de =
@@ -1249,7 +1253,7 @@ incore_unlink_entry(struct incore_inode *icino,
        if (!de)
                return -ENOENT;
        assert((size_t )((char *)de - (char *)icino->ici_data) >=
-              sizeof(incore_dir_template));
+              INCORE_D_TEMPLATE_LEN);
 #ifndef _DIRENT_HAVE_D_OFF
        reclen = de->d_reclen;
 #else
index 95eab24..613ea29 100644 (file)
@@ -163,6 +163,7 @@ struct filesys {
 
 extern struct fsswent *_sysio_fssw_lookup(const char *name);
 extern int _sysio_fssw_register(const char *name, struct fssw_ops *ops);
+extern char *incore_dir_template;
 extern struct filesys * _sysio_fs_new(struct filesys_ops *ops,
                                      unsigned mask,
                                      void *private);
index 0708a96..6dc4f29 100644 (file)
@@ -219,6 +219,7 @@ _sysio_shutdown()
        _sysio_i_shutdown();
        _sysio_fssw_shutdown();
        _sysio_access_shutdown();
+       free(incore_dir_template);
 #ifdef SYSIO_TRACING
        {
                struct trace_callback *tcb;