Flexible array checking can additionally probe that the size
of the array element is correct.
Lustre-change: https://review.whamcloud.com/54929
Lustre-commit:
339b585c257d7f47d0c9b74f9d940fd20b8c04a3
Was-Change-Id: Ib7de3d156a2e77dfaf2e9ab1df8fab524c073610
LU-17504 libcfs: safer LIBCFS_ALLOC
Make the LIBCFS_ALLOC() family of macros safer by adding
parenthesis around arguments such as (size) to avoid uninteded
expansion.
CoverityID: 415056 ("Integer handling issues")
Lustre-change: https://review.whamcloud.com/55015
Lustre-commit:
0d3a9607655adc8f9dd4ae1c341bde0b57fe88bf
Was-Change-Id: I9701f87025bc5ce038a6bf34413b64a3f019d998
Fixes:
718e3f3e68 ("LU-17504 build: fix gcc-13 [-Werror=stringop-overread] error")
LU-17504 build: fix lock_handle array-index-out-of-bounds
After Linux kernel patch "ubsan: Tighten UBSAN_BOUNDS on GCC"
(commit v6.4-rc2-1-g2d47c6956ab3), flexible trailing arrays
declared like 'lock_handle[2]' will generate warnings when
CONFIG_UBSAN & co. is enabled:
UBSAN: array-index-out-of-bounds in ldlm_request.c:1282:18
index 2 is out of range for type 'lustre_handle [2]'
The declaration lock_handle[LDLM_LOCKREQ_HANDLES] confuses the
compiler into thinking there are only two fields in lock_handle,
but the caller often allocates extra fields beyond this for more
locks to be cancelled due to Early Lock Cancellation or from LRU.
Rather than have a second flexible array after lustre_handle[2],
declare the whole array as flexible, and fix up the few sites
that are allocating this array to ensure LDLM_LOCKREQ_HANDLES
fields are allocated at a minimum.
This subtly changes the checks in wiretest.c due to the removal
of the 2 "base" handles in ldlm_request, but I believe this is not
changing the wire protocol because it still allocates those handles
directly, and I have verified interoperability with a 2.14.0 server.
Lustre-change: https://review.whamcloud.com/54926
Lustre-commit:
e3a9d87370c4ccc58d1d3a97ea1b221d88f9e57a
Was-Change-Id: I9695fb44f1b5c84bb750d2983cdd8b939e3ebbe5
Test-Parameters: testlist=runtests clientversion=2.14
Test-Parameters: testlist=runtests serverversion=2.14
Test-Parameters: testlist=runtests clientversion=2.15
Test-Parameters: testlist=runtests serverversion=2.15
Test-Parameters: testlist=runtests clientversion=EXA5
Test-Parameters: testlist=runtests serverversion=EXA5
Test-Parameters: testlist=runtests clientversion=EXA6
Test-Parameters: testlist=runtests serverversion=EXA6
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
LU-17504 build: fix gcc-13 [-Werror=stringop-overread] error
This patch fixes the following [-Werror=stringop-overread] and
[-Werror=attribute-warning] errors detected by gcc 13:
lustre/mgc/mgc_request.c:190:21: error: 'strcmp' reading 1 or
more bytes from a region of size 0 [-Werror=stringop-overread]
190 | if (strcmp(logname, cld->cld_logname) == 0) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'fortify_memcpy_chk',
inlined from 'class_handle_ioctl' at
/root/lustre-release/lustre/obdclass/class_obd.c:381:3:
include/linux/fortify-string.h:528:25: error:
call to '__write_overflow_field' declared with attribute warning:
detected write beyond size of field (1st parameter);
maybe use struct_group()? [-Werror=attribute-warning]
528 | __write_overflow_field(p_size_field, size);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lustre-change: https://review.whamcloud.com/54834
Lustre-commit:
718e3f3e680f422d865a15890ac60e66dcd9e240
Was-Change-Id: I59f5a88b4cd64c9f4e67e568546baada371543b1
Signed-off-by: Jian Yu <yujian@whamcloud.com>
LU-17504 build: fix array-index-out-of-bounds warning
On Linux kernel 6.5, due to commit
2d47c6956ab3
("ubsan: Tighten UBSAN_BOUNDS on GCC"), flexible
trailing arrays declared like 'lc_array_sum[1];'
will generate warnings when CONFIG_UBSAN & co. is
enabled:
UBSAN: array-index-out-of-bounds in lprocfs_status.c:1609:17
index 1 is out of range for type '__s64 [1]'
Since LPROCFS_STATS_FLAG_IRQ_SAFE flag is only used
in one place - obd_memory() counter, we can just
remove it and change obd_memory over to a regular
percpu_counter. This would both simplify the
lprocfs_counter() code, move over to using more
kernel functionality instead of libcfs, as well as
reduce overhead slightly for the memory accounting code.
Lustre-change: https://review.whamcloud.com/54365
Lustre-commit:
b698abd415bc4a810f307611fe984e50e007581e
Was-Change-Id: Ic461c4b30317bfd2b1e9f5b6be84c4a7fb4e3eb9
Signed-off-by: Jian Yu <yujian@whamcloud.com>
LU-16363 build: fiemap flexible array
Linux commit v5.19-rc2-1-g94dfc73e7cf4
treewide: uapi: Replace zero-length arrays with flexible-array
members
Adjust wiretest to handle flexible array when
sizeof(fiemap->fm_extents) is undefined.
Lustre-change: https://review.whamcloud.com/49305
Lustre-commit:
fedf1e8bd70ccb2aaa64cb90111a7298d9bb2bf7
Was-Change-Id: Ia2692d126a871b43e9144e5d151215166604702d
HPE-bug-id: LUS-11388
Signed-off-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Change-Id: Ib7de3d156a2e77dfaf2e9ab1df8fab524c073610
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/59303
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Yang Sheng <ys@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
/** workitem to output max depth */
struct work_struct hs_dep_work;
#endif
- /** name of htable */
- char hs_name[0];
+ /** name of htable */
+ char hs_name[];
};
struct cfs_hash_lock_ops {
# define libcfs_kmem_inc(ptr, size) \
do { \
- atomic64_add(size, &libcfs_kmem); \
+ atomic64_add((size), &libcfs_kmem); \
} while (0)
# define libcfs_kmem_dec(ptr, size) \
do { \
- atomic64_sub(size, &libcfs_kmem); \
+ atomic64_sub((size), &libcfs_kmem); \
} while (0)
# define libcfs_kmem_read() \
* default allocator
*/
#define LIBCFS_ALLOC(ptr, size) \
- LIBCFS_ALLOC_GFP(ptr, size, GFP_NOFS)
+ LIBCFS_ALLOC_GFP(ptr, (size), GFP_NOFS)
/**
* non-sleeping allocator
*/
#define LIBCFS_ALLOC_ATOMIC(ptr, size) \
- LIBCFS_ALLOC_GFP(ptr, size, GFP_ATOMIC)
+ LIBCFS_ALLOC_GFP(ptr, (size), GFP_ATOMIC)
/**
* allocate memory for specified CPU partition
/** default numa allocator */
#define LIBCFS_CPT_ALLOC(ptr, cptab, cpt, size) \
- LIBCFS_CPT_ALLOC_GFP(ptr, cptab, cpt, size, GFP_NOFS)
+ LIBCFS_CPT_ALLOC_GFP(ptr, (cptab), (cpt), (size), GFP_NOFS)
#define LIBCFS_FREE(ptr, size) \
do { \
len = (flags & CFS_HASH_BIGNAME) == 0 ?
CFS_HASH_NAME_LEN : CFS_HASH_BIGNAME_LEN;
- LIBCFS_ALLOC(hs, offsetof(struct cfs_hash, hs_name[len]));
+ LIBCFS_ALLOC(hs, sizeof(struct cfs_hash) + len);
if (hs == NULL)
RETURN(NULL);
if (hs->hs_buckets != NULL)
return hs;
- LIBCFS_FREE(hs, offsetof(struct cfs_hash, hs_name[len]));
+ LIBCFS_FREE(hs, sizeof(struct cfs_hash) + len);
RETURN(NULL);
}
EXPORT_SYMBOL(cfs_hash_create);
0, CFS_HASH_NBKT(hs));
i = cfs_hash_with_bigname(hs) ?
CFS_HASH_BIGNAME_LEN : CFS_HASH_NAME_LEN;
- LIBCFS_FREE(hs, offsetof(struct cfs_hash, hs_name[i]));
+ LIBCFS_FREE(hs, sizeof(struct cfs_hash) + i);
EXIT;
}
AS_IF([test $ENABLEO2IB != "no"], [
EXTRA_CHECK_INCLUDE="$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE"
- if test ! $O2IBPATH -ef $LINUX_OBJ; then
+ if test ! $O2IBPATH -ef $LINUX_OBJ &&
+ test -f $O2IBPATH/Module.symvers; then
KBUILD_EXTRA_SYMBOLS="$KBUILD_EXTRA_SYMBOLS $O2IBPATH/Module.symvers"
fi
struct lnet_text_buf {
struct list_head ltb_list; /* stash on lists */
int ltb_size; /* allocated size */
- char ltb_text[0]; /* text buffer */
+ char ltb_text[]; /* text buffer */
};
static int lnet_tbnob = 0; /* track text buf allocation */
}
}
-void
+static void
lnet_selftest_structure_assertion(void)
{
BUILD_BUG_ON(sizeof(struct srpc_msg) != 160);
int rc = -ENOMEM;
int i;
+ /* This assertion checks that struct sizes do not drift
+ * inadvertently and induce crashes when different nodes
+ * running LNet Selftest have mismatched structures.
+ */
+ lnet_selftest_structure_assertion();
+
lst_serial_wq = alloc_ordered_workqueue("lst_s", 0);
if (!lst_serial_wq) {
CERROR("Failed to create serial WI scheduler for LST\n");
]) # LC_HAVE_CRYPTO_MAX_ALG_NAME_128
#
+# LC_HAVE_PERCPU_COUNTER_ADD_BATCH
+#
+# Linux commit v4.11-12447-g104b4e5139fe
+# percpu_counter: Rename __percpu_counter_add to percpu_counter_add_batch
+#
+AC_DEFUN([LC_SRC_HAVE_PERCPU_COUNTER_ADD_BATCH], [
+ LB2_LINUX_TEST_SRC([percpu_counter_add_batch_exists], [
+ #include <linux/percpu_counter.h>
+ ],[
+ (void)percpu_counter_add_batch(NULL, 0, 0);
+ ],[-Werror])
+])
+AC_DEFUN([LC_HAVE_PERCPU_COUNTER_ADD_BATCH], [
+ AC_MSG_CHECKING([if 'percpu_counter_add_batch()' exists])
+ LB2_LINUX_TEST_RESULT([percpu_counter_add_batch_exists], [
+ AC_DEFINE(HAVE_PERCPU_COUNTER_ADD_BATCH, 1,
+ ['percpu_counter_add_batch()' exists])
+ ])
+]) # LC_HAVE_PERCPU_COUNTER_ADD_BATCH
+
+#
# LC_CURRENT_TIME
#
# Kernel version 4.12 commit 47f38c539e9a42344ff5a664942075bd4df93876
LC_SRC_VM_OPERATIONS_REMOVE_VMF_ARG
LC_SRC_HAVE_KEY_USAGE_REFCOUNT
LC_SRC_HAVE_CRYPTO_MAX_ALG_NAME_128
+ LC_SRC_HAVE_PERCPU_COUNTER_ADD_BATCH
# 4.12
LC_SRC_CURRENT_TIME
LC_VM_OPERATIONS_REMOVE_VMF_ARG
LC_HAVE_KEY_USAGE_REFCOUNT
LC_HAVE_CRYPTO_MAX_ALG_NAME_128
+ LC_HAVE_PERCPU_COUNTER_ADD_BATCH
# 4.12
LC_CURRENT_TIME
__s64 lc_count;
__s64 lc_min;
__s64 lc_max;
+ __s64 lc_sum;
__s64 lc_sumsquare;
- /*
- * Every counter has lc_array_sum[0], while lc_array_sum[1] is only
- * for irq context counter, i.e. stats with
- * LPROCFS_STATS_FLAG_IRQ_SAFE flag, its counter need
- * lc_array_sum[1]
- */
- __s64 lc_array_sum[1];
};
-#define lc_sum lc_array_sum[0]
-#define lc_sum_irq lc_array_sum[1]
struct lprocfs_percpu {
struct lprocfs_counter lp_cntr[0];
LPROCFS_STATS_FLAG_NONE = 0x0000, /* per cpu counter */
LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
* area and need locking */
- LPROCFS_STATS_FLAG_IRQ_SAFE = 0x0002, /* alloc need irq safe */
};
enum lprocfs_fields_flags {
percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
- /* irq safe stats need lc_array_sum[1] */
- if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
- percpusize += stats->ls_num * sizeof(__s64);
-
if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
percpusize = L1_CACHE_ALIGN(percpusize);
cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
- if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
- cntr = (void *)cntr + index * sizeof(__s64);
-
return cntr;
}
unsigned int cld_stopping:1, /* we were told to stop
* watching */
cld_lostlock:1; /* lock not requeued */
- char cld_logname[0];
+ char cld_logname[];
};
struct lustre_profile {
#include <linux/highmem.h>
#include <linux/slab.h>
#include <linux/types.h>
+#include <linux/percpu_counter.h>
#include <libcfs/libcfs.h>
#include <lnet/lib-cpt.h>
#include <lustre_handles.h>
/* global variables */
-extern struct lprocfs_stats *obd_memory;
-enum {
- OBD_MEMORY_STAT = 0,
- OBD_STATS_NUM,
-};
+extern struct percpu_counter obd_memory;
extern unsigned int obd_debug_peer_on_timeout;
extern unsigned int obd_dump_on_timeout;
extern atomic64_t libcfs_kmem;
-#ifdef CONFIG_PROC_FS
-#define obd_memory_add(size) \
- lprocfs_counter_add(obd_memory, OBD_MEMORY_STAT, (long)(size))
-#define obd_memory_sub(size) \
- lprocfs_counter_sub(obd_memory, OBD_MEMORY_STAT, (long)(size))
-#define obd_memory_sum() \
- lprocfs_stats_collector(obd_memory, OBD_MEMORY_STAT, \
- LPROCFS_FIELDS_FLAGS_SUM)
-
-extern void obd_update_maxusage(void);
-extern __u64 obd_memory_max(void);
-
-#else /* CONFIG_PROC_FS */
-
-extern __u64 obd_alloc;
+/* OBD_MEMORY_BATCH is the maximum error allowed per CPU core. Since
+ * obd_memory_sum() is calling percpu_counter_sum_positive(), it adds
+ * up the per-core local delta anyway, so the per-core batch size is
+ * can be large. This could be percpu_counter_add_local(), but that
+ * only exists in kernel 6.0 and later, and just uses a larger batch.
+ */
+#define OBD_MEMORY_BATCH (16 * 1024 * 1024)
-extern __u64 obd_max_alloc;
+#ifndef HAVE_PERCPU_COUNTER_ADD_BATCH
+#define percpu_counter_add_batch(fbc, amount, batch) \
+ __percpu_counter_add(fbc, amount, batch)
+#endif
-static inline void obd_memory_add(long size)
+static inline void obd_memory_add(size_t size)
{
- obd_alloc += size;
- if (obd_alloc > obd_max_alloc)
- obd_max_alloc = obd_alloc;
+ percpu_counter_add_batch(&obd_memory, size, OBD_MEMORY_BATCH);
}
-static inline void obd_memory_sub(long size)
+static inline void obd_memory_sub(size_t size)
{
- obd_alloc -= size;
+ percpu_counter_add_batch(&obd_memory, -size, OBD_MEMORY_BATCH);
}
-#define obd_memory_sum() (obd_alloc)
-
-#define obd_memory_max() (obd_max_alloc)
+static inline s64 obd_memory_sum(void)
+{
+ return percpu_counter_sum_positive(&obd_memory);
+}
-#endif /* !CONFIG_PROC_FS */
+extern void obd_update_maxusage(void);
+extern __u64 obd_memory_max(void);
#define OBD_DEBUG_MEMUSAGE (1)
* their natural order. After the last attribute, padding bytes are
* added to make ->lde_reclen a multiple of 8.
*/
- char lde_name[0];
+ char lde_name[];
};
/*
struct ldlm_request {
__u32 lock_flags; /* LDLM_FL_*, see lustre_dlm_flags.h */
__u32 lock_count; /* number of locks in lock_handle[] */
- struct ldlm_lock_desc lock_desc;/* lock descriptor */
- struct lustre_handle lock_handle[LDLM_LOCKREQ_HANDLES];
+ struct ldlm_lock_desc lock_desc; /* lock descriptor */
+ struct lustre_handle lock_handle[]; /* was LDLM_LOCKREQ_HANDLES */
};
struct ldlm_reply {
* - the record size (II_FL_VARREC is set)
*
* For the time being, we only support fixed-size key & record. */
- char lip_entries[0];
+ char lip_entries[];
};
#define LIP_HDR_SIZE (offsetof(struct lu_idxpage, lip_entries))
__u16 oup_len; /* length of this parameter */
__u16 oup_padding;
__u32 oup_padding2;
- char oup_buf[0];
+ char oup_buf[];
} __attribute__((packed));
/* object update */
__u32 ou_padding1; /* padding 1 */
__u64 ou_batchid; /* op transno on master */
struct lu_fid ou_fid; /* object to be updated */
- struct object_update_param ou_params[0]; /* update params */
+ struct object_update_param ou_params[]; /* update params */
};
#define UPDATE_REQUEST_MAGIC_V1 0xBDDE0001
__u32 ourq_magic;
__u16 ourq_count; /* number of ourq_updates[] */
__u16 ourq_padding;
- struct object_update ourq_updates[0];
+ struct object_update ourq_updates[];
};
#define OUT_UPDATE_HEADER_MAGIC 0xBDDF0001
__u32 ouh_count;
__u32 ouh_inline_length;
__u32 ouh_reply_size;
- __u32 ouh_inline_data[0];
+ __u32 ouh_inline_data[];
};
struct out_update_buffer {
__u32 our_rc;
__u16 our_datalen;
__u16 our_padding;
- __u32 our_data[0];
+ __u32 our_data[];
};
#define UPDATE_REPLY_MAGIC_V1 0x00BD0001
__u32 ourp_magic;
__u16 ourp_count;
__u16 ourp_padding;
- __u16 ourp_lens[0];
+ __u16 ourp_lens[];
};
/* read update result */
__u32 orr_size;
__u32 orr_padding;
__u64 orr_offset;
- char orr_data[0];
+ char orr_data[];
};
/** layout swap request structure
__u32 ioc_inllen4;
char *ioc_inlbuf4;
- char ioc_bulk[0];
+ char ioc_bulk[];
};
struct obd_ioctl_hdr {
__u16 lcm_mirror_count;
__u16 lcm_padding1[3];
__u64 lcm_padding2;
- struct lov_comp_md_entry_v1 lcm_entries[0];
+ struct lov_comp_md_entry_v1 lcm_entries[];
} __attribute__((packed));
static inline __u32 lov_user_md_size(__u16 stripes, __u32 lmm_magic)
__u64 hal_flags;
__u32 hal_archive_id; /* which archive backend */
__u32 padding1;
- char hal_fsname[0]; /* null-terminated */
+ char hal_fsname[]; /* null-terminated */
/* struct hsm_action_item[hal_count] follows, aligned on 8-byte
boundaries. See hai_zero */
} __attribute__((packed));
ENTRY;
size = req_capsule_get_size(&req->rq_pill, &RMF_DLM_REQ, RCL_CLIENT);
- if (size <= offsetof(struct ldlm_request, lock_handle) ||
- (size - offsetof(struct ldlm_request, lock_handle)) /
- sizeof(struct lustre_handle) < dlm_req->lock_count)
+ if (size <= sizeof(*dlm_req) || dlm_req->lock_count >
+ (size - sizeof(*dlm_req)) / sizeof(struct lustre_handle))
RETURN(0);
count = dlm_req->lock_count ? dlm_req->lock_count : 1;
* LDLM_LOCKREQ_HANDLE -1 slots are available.
* Otherwise, LDLM_LOCKREQ_HANDLE slots are available.
*
- * \param[in] count
- * \param[in] type
+ * \param[in] count - total number of lock handles to include for cancel
+ * \param[in] type - LDLM RPC request type
*
* \retval size of the request buffer
*/
int ldlm_request_bufsize(int count, int type)
{
- int avail = LDLM_LOCKREQ_HANDLES;
-
if (type == LDLM_ENQUEUE)
- avail -= LDLM_ENQUEUE_CANCEL_OFF;
+ count++;
- if (count > avail)
- avail = (count - avail) * sizeof(struct lustre_handle);
- else
- avail = 0;
+ /* keep minimum handles to keep struct size for compatibility */
+ if (count < LDLM_LOCKREQ_HANDLES)
+ count = LDLM_LOCKREQ_HANDLES;
- return sizeof(struct ldlm_request) + avail;
+ return offsetof(struct ldlm_request, lock_handle[count]);
}
void ldlm_expired_completion_wait(struct lock_wait_data *lwd)
__u32 lnr_size;
__u16 lnr_type;
__u16 lnr_namelen;
- char lnr_name[0];
+ char lnr_name[];
};
struct lfsck_layout_req {
{
struct config_llog_data *cld;
int rc;
+ int logname_size;
ENTRY;
CDEBUG(D_MGC, "do adding config log %s-%016lx\n", logname,
cfg ? cfg->cfg_instance : 0);
- OBD_ALLOC(cld, sizeof(*cld) + strlen(logname) + 1);
+ logname_size = strlen(logname) + 1;
+ OBD_ALLOC(cld, sizeof(*cld) + logname_size);
if (!cld)
RETURN(ERR_PTR(-ENOMEM));
rc = mgc_logname2resid(logname, &cld->cld_resid, type);
if (rc) {
- OBD_FREE(cld, sizeof(*cld) + strlen(cld->cld_logname) + 1);
+ OBD_FREE(cld, sizeof(*cld) + logname_size);
RETURN(ERR_PTR(rc));
}
- strcpy(cld->cld_logname, logname);
+ strscpy(cld->cld_logname, logname, logname_size);
if (cfg)
cld->cld_cfg = *cfg;
else
#include <uapi/linux/lustre/lustre_ioctl.h>
#include "llog_internal.h"
-#ifdef CONFIG_PROC_FS
static __u64 obd_max_alloc;
-#else
-__u64 obd_max_alloc;
-#endif
static DEFINE_SPINLOCK(obd_updatemax_lock);
int at_extra = 30;
EXPORT_SYMBOL(at_extra);
-#ifdef CONFIG_PROC_FS
-struct lprocfs_stats *obd_memory = NULL;
+struct percpu_counter obd_memory;
EXPORT_SYMBOL(obd_memory);
-#endif
static int obdclass_oom_handler(struct notifier_block *self,
unsigned long notused, void *nfreed)
{
-#ifdef CONFIG_PROC_FS
/* in bytes */
pr_info("obd_memory max: %llu, obd_memory current: %llu\n",
obd_memory_max(), obd_memory_sum());
-#endif /* CONFIG_PROC_FS */
return NOTIFY_OK;
}
#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
case OBD_GET_VERSION: {
static bool warned;
+ size_t vstr_size = sizeof(LUSTRE_VERSION_STRING);
if (!data->ioc_inlbuf1) {
CERROR("No buffer passed in ioctl\n");
GOTO(out, err = -EINVAL);
}
- if (strlen(LUSTRE_VERSION_STRING) + 1 > data->ioc_inllen1) {
+ if (vstr_size > data->ioc_inllen1) {
CERROR("ioctl buffer too small to hold version\n");
GOTO(out, err = -EINVAL);
}
"use llapi_get_version_string() and/or relink\n",
current->comm);
}
- memcpy(data->ioc_bulk, LUSTRE_VERSION_STRING,
- strlen(LUSTRE_VERSION_STRING) + 1);
+
+ strscpy(data->ioc_bulk, LUSTRE_VERSION_STRING, vstr_size);
if (copy_to_user((void __user *)arg, data, len))
err = -EFAULT;
if (err)
return err;
-#ifdef CONFIG_PROC_FS
- obd_memory = lprocfs_alloc_stats(OBD_STATS_NUM,
- LPROCFS_STATS_FLAG_NONE |
- LPROCFS_STATS_FLAG_IRQ_SAFE);
- if (obd_memory == NULL) {
- CERROR("kmalloc of 'obd_memory' failed\n");
- return -ENOMEM;
+ err = percpu_counter_init(&obd_memory, 0, GFP_KERNEL);
+ if (err < 0) {
+ CERROR("obdclass: initializing 'obd_memory' failed: rc = %d\n",
+ err);
+ return err;
}
- lprocfs_counter_init(obd_memory, OBD_MEMORY_STAT,
- LPROCFS_CNTR_AVGMINMAX | LPROCFS_TYPE_BYTES,
- "memused");
-#endif
err = obd_zombie_impexp_init();
if (err)
goto cleanup_obd_memory;
err = misc_register(&obd_psdev);
if (err) {
- CERROR("cannot register OBD miscdevice: err = %d\n", err);
+ CERROR("cannot register OBD miscdevice: rc = %d\n", err);
goto cleanup_class_handle;
}
obd_zombie_impexp_stop();
cleanup_obd_memory:
-#ifdef CONFIG_PROC_FS
- lprocfs_free_stats(&obd_memory);
-#endif
+ percpu_counter_destroy(&obd_memory);
unregister_oom_notifier(&obdclass_oom);
return err;
}
EXPORT_SYMBOL(obd_update_maxusage);
-#ifdef CONFIG_PROC_FS
__u64 obd_memory_max(void)
{
__u64 ret;
return ret;
}
-#endif /* CONFIG_PROC_FS */
+EXPORT_SYMBOL(obd_memory_max);
static void __exit obdclass_exit(void)
{
-#ifdef CONFIG_PROC_FS
__u64 memory_leaked;
__u64 memory_max;
-#endif /* CONFIG_PROC_FS */
ENTRY;
misc_deregister(&obd_psdev);
class_del_uuid(NULL); /* Delete all UUIDs. */
obd_zombie_impexp_stop();
-#ifdef CONFIG_PROC_FS
memory_leaked = obd_memory_sum();
memory_max = obd_memory_max();
- lprocfs_free_stats(&obd_memory);
+ percpu_counter_destroy(&obd_memory);
/* the below message is checked in test-framework.sh check_mem_leak() */
CDEBUG((memory_leaked) ? D_ERROR : D_INFO,
"obd_memory max: %llu, leaked: %llu\n",
memory_max, memory_leaked);
-#endif /* CONFIG_PROC_FS */
unregister_oom_notifier(&obdclass_oom);
{
struct idx_info *ii = (struct idx_info *)arg;
struct lu_idxpage *lip = &lp->lp_idx;
- char *entry;
+ void *entry;
__u64 hash;
__u16 hashsize = 0;
__u16 keysize = 0;
* as memory allocation could trigger memory shrinker call
* ldlm_pool_shrink(), which calls lprocfs_counter_add().
* LU-1727.
- *
- * Only obd_memory uses LPROCFS_STATS_FLAG_IRQ_SAFE
- * flag, because it needs accurate counting lest memory leak
- * check reports error.
*/
- if (in_interrupt() &&
- (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
- percpu_cntr->lc_sum_irq += amount;
- else
- percpu_cntr->lc_sum += amount;
+ percpu_cntr->lc_sum += amount;
if (header->lc_config & LPROCFS_CNTR_STDDEV)
percpu_cntr->lc_sumsquare += (__s64)amount * amount;
* softirq context - right now that's the only case we're in
* softirq context here, use separate counter for that.
* bz20650.
- *
- * Only obd_memory uses LPROCFS_STATS_FLAG_IRQ_SAFE
- * flag, because it needs accurate counting lest memory leak
- * check reports error.
*/
- if (in_interrupt() &&
- (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
- percpu_cntr->lc_sum_irq -= amount;
- else
- percpu_cntr->lc_sum -= amount;
+ percpu_cntr->lc_sum -= amount;
}
lprocfs_stats_unlock(stats, LPROCFS_GET_SMP_ID, &flags);
}
unsigned long *flags)
{
if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
- if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
- spin_lock_irqsave(&stats->ls_lock, *flags);
- else
- spin_lock(&stats->ls_lock);
+ spin_lock(&stats->ls_lock);
return opc == LPROCFS_GET_NUM_CPU ? 1 : 0;
}
unsigned long *flags)
{
if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
- if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
- spin_unlock_irqrestore(&stats->ls_lock, *flags);
- else
- spin_unlock(&stats->ls_lock);
+ spin_unlock(&stats->ls_lock);
} else if (opc == LPROCFS_GET_SMP_ID) {
put_cpu();
}
struct lprocfs_counter *cntr;
unsigned int percpusize;
int rc = -ENOMEM;
- unsigned long flags = 0;
int i;
LASSERT(stats->ls_percpu[cpuid] == NULL);
if (stats->ls_percpu[cpuid]) {
rc = 0;
if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
- if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
- spin_lock_irqsave(&stats->ls_lock, flags);
- else
- spin_lock(&stats->ls_lock);
+ spin_lock(&stats->ls_lock);
if (stats->ls_biggest_alloc_num <= cpuid)
stats->ls_biggest_alloc_num = cpuid + 1;
- if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
- spin_unlock_irqrestore(&stats->ls_lock, flags);
- } else {
- spin_unlock(&stats->ls_lock);
- }
+ spin_unlock(&stats->ls_lock);
}
/* initialize the ls_percpu[cpuid] non-zero counter */
for (i = 0; i < stats->ls_num; ++i) {
struct lprocfs_stats *stats;
unsigned int num_entry;
unsigned int percpusize = 0;
- int i;
if (num == 0)
return NULL;
if (!stats->ls_percpu[0])
goto fail;
stats->ls_biggest_alloc_num = 1;
- } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
- /* alloc all percpu data, currently only obd_memory use this */
- for (i = 0; i < num_entry; ++i)
- if (lprocfs_stats_alloc_one(stats, i) < 0)
- goto fail;
}
return stats;
percpu_cntr->lc_max = 0;
percpu_cntr->lc_sumsquare = 0;
percpu_cntr->lc_sum = 0;
- if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
- percpu_cntr->lc_sum_irq = 0;
}
}
stats->ls_init = ktime_get_real();
percpu_cntr->lc_max = 0;
percpu_cntr->lc_sumsquare = 0;
percpu_cntr->lc_sum = 0;
- if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
- percpu_cntr->lc_sum_irq = 0;
}
lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
}
break;
case LPROCFS_FIELDS_FLAGS_SUM:
ret = lc->lc_sum;
- if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
- ret += lc->lc_sum_irq;
break;
case LPROCFS_FIELDS_FLAGS_MIN:
ret = lc->lc_min;
ret = lc->lc_max;
break;
case LPROCFS_FIELDS_FLAGS_AVG:
- ret = div64_u64((flags & LPROCFS_STATS_FLAG_IRQ_SAFE ?
- lc->lc_sum_irq : 0) + lc->lc_sum,
- lc->lc_count);
+ ret = div64_u64(lc->lc_sum, lc->lc_count);
break;
case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
ret = lc->lc_sumsquare;
struct req_msg_field RMF_DLM_REQ =
DEFINE_MSGF("dlm_req", RMF_F_NO_SIZE_CHECK /* ldlm_request_bufsize */,
- sizeof(struct ldlm_request),
+ offsetof(struct ldlm_request,
+ lock_handle[LDLM_LOCKREQ_HANDLES]),
lustre_swab_ldlm_request, NULL);
EXPORT_SYMBOL(RMF_DLM_REQ);
(long long)(int)offsetof(struct lov_comp_md_v1, lcm_padding2));
LASSERTF((int)sizeof(((struct lov_comp_md_v1 *)0)->lcm_padding2) == 8, "found %lld\n",
(long long)(int)sizeof(((struct lov_comp_md_v1 *)0)->lcm_padding2));
- LASSERTF((int)offsetof(struct lov_comp_md_v1, lcm_entries[0]) == 32, "found %lld\n",
- (long long)(int)offsetof(struct lov_comp_md_v1, lcm_entries[0]));
- LASSERTF((int)sizeof(((struct lov_comp_md_v1 *)0)->lcm_entries[0]) == 48, "found %lld\n",
- (long long)(int)sizeof(((struct lov_comp_md_v1 *)0)->lcm_entries[0]));
+ LASSERTF((int)offsetof(struct lov_comp_md_v1, lcm_entries) == 32, "found %lld\n",
+ (long long)(int)offsetof(struct lov_comp_md_v1, lcm_entries));
+ LASSERTF((int)sizeof(*((struct lov_comp_md_v1 *)0)->lcm_entries) == 48, "found %lld\n",
+ (long long)(int)sizeof(*((struct lov_comp_md_v1 *)0)->lcm_entries));
+ BUILD_BUG_ON(offsetof(struct lov_comp_md_v1, lcm_entries) != sizeof(struct lov_comp_md_v1));
BUILD_BUG_ON(LOV_MAGIC_COMP_V1 != (0x0BD60000 | 0x0BD0));
LASSERTF(LCM_FL_NONE == 0, "found %lld\n",
(long long)LCM_FL_NONE);
(long long)(int)sizeof(((struct ldlm_lock_desc *)0)->l_policy_data));
/* Checks for struct ldlm_request */
- LASSERTF((int)sizeof(struct ldlm_request) == 104, "found %lld\n",
+ LASSERTF((int)sizeof(struct ldlm_request) == 88, "found %lld\n",
(long long)(int)sizeof(struct ldlm_request));
LASSERTF((int)offsetof(struct ldlm_request, lock_flags) == 0, "found %lld\n",
(long long)(int)offsetof(struct ldlm_request, lock_flags));
(long long)(int)sizeof(((struct ldlm_request *)0)->lock_desc));
LASSERTF((int)offsetof(struct ldlm_request, lock_handle) == 88, "found %lld\n",
(long long)(int)offsetof(struct ldlm_request, lock_handle));
- LASSERTF((int)sizeof(((struct ldlm_request *)0)->lock_handle) == 16, "found %lld\n",
- (long long)(int)sizeof(((struct ldlm_request *)0)->lock_handle));
+ LASSERTF((int)sizeof(*((struct ldlm_request *)0)->lock_handle) == 8, "found %lld\n",
+ (long long)(int)sizeof(*((struct ldlm_request *)0)->lock_handle));
+ BUILD_BUG_ON(offsetof(struct ldlm_request, lock_handle) != sizeof(struct ldlm_request));
/* Checks for struct ldlm_reply */
LASSERTF((int)sizeof(struct ldlm_reply) == 112, "found %lld\n",
(long long)(int)sizeof(((struct fiemap *)0)->fm_reserved));
LASSERTF((int)offsetof(struct fiemap, fm_extents) == 32, "found %lld\n",
(long long)(int)offsetof(struct fiemap, fm_extents));
- LASSERTF((int)sizeof(((struct fiemap *)0)->fm_extents) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct fiemap *)0)->fm_extents));
+ LASSERTF((int)sizeof(*((struct fiemap *)0)->fm_extents) == 56, "found %lld\n",
+ (long long)(int)sizeof(*((struct fiemap *)0)->fm_extents));
+ BUILD_BUG_ON(offsetof(struct fiemap, fm_extents) != sizeof(struct fiemap));
BUILD_BUG_ON(FIEMAP_FLAG_SYNC != 0x00000001);
BUILD_BUG_ON(FIEMAP_FLAG_XATTR != 0x00000002);
BUILD_BUG_ON(FIEMAP_FLAG_DEVICE_ORDER != 0x40000000);
(long long)(int)sizeof(((struct hsm_action_list *)0)->padding1));
LASSERTF((int)offsetof(struct hsm_action_list, hal_fsname) == 32, "found %lld\n",
(long long)(int)offsetof(struct hsm_action_list, hal_fsname));
- LASSERTF((int)sizeof(((struct hsm_action_list *)0)->hal_fsname) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct hsm_action_list *)0)->hal_fsname));
+ LASSERTF((int)sizeof(*((struct hsm_action_list *)0)->hal_fsname) == 1, "found %lld\n",
+ (long long)(int)sizeof(*((struct hsm_action_list *)0)->hal_fsname));
+ BUILD_BUG_ON(offsetof(struct hsm_action_list, hal_fsname) != sizeof(struct hsm_action_list));
/* Checks for struct hsm_progress */
LASSERTF((int)sizeof(struct hsm_progress) == 48, "found %lld\n",
(long long)(int)sizeof(((struct object_update_param *)0)->oup_padding2));
LASSERTF((int)offsetof(struct object_update_param, oup_buf) == 8, "found %lld\n",
(long long)(int)offsetof(struct object_update_param, oup_buf));
- LASSERTF((int)sizeof(((struct object_update_param *)0)->oup_buf) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct object_update_param *)0)->oup_buf));
+ LASSERTF((int)sizeof(*((struct object_update_param *)0)->oup_buf) == 1, "found %lld\n",
+ (long long)(int)sizeof(*((struct object_update_param *)0)->oup_buf));
+ BUILD_BUG_ON(offsetof(struct object_update_param, oup_buf) != sizeof(struct object_update_param));
/* Checks for struct object_update */
LASSERTF((int)sizeof(struct object_update) == 40, "found %lld\n",
(long long)(int)sizeof(((struct object_update *)0)->ou_fid));
LASSERTF((int)offsetof(struct object_update, ou_params) == 40, "found %lld\n",
(long long)(int)offsetof(struct object_update, ou_params));
- LASSERTF((int)sizeof(((struct object_update *)0)->ou_params) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct object_update *)0)->ou_params));
+ LASSERTF((int)sizeof(*((struct object_update *)0)->ou_params) == 8, "found %lld\n",
+ (long long)(int)sizeof(*((struct object_update *)0)->ou_params));
+ BUILD_BUG_ON(offsetof(struct object_update, ou_params) != sizeof(struct object_update));
BUILD_BUG_ON(UPDATE_FL_OST != 0x00000001);
BUILD_BUG_ON(UPDATE_FL_SYNC != 0x00000002);
BUILD_BUG_ON(UPDATE_FL_COMMITTED != 0x00000004);
(long long)(int)sizeof(((struct object_update_request *)0)->ourq_padding));
LASSERTF((int)offsetof(struct object_update_request, ourq_updates) == 8, "found %lld\n",
(long long)(int)offsetof(struct object_update_request, ourq_updates));
- LASSERTF((int)sizeof(((struct object_update_request *)0)->ourq_updates) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct object_update_request *)0)->ourq_updates));
+ LASSERTF((int)sizeof(*((struct object_update_request *)0)->ourq_updates) == 40, "found %lld\n",
+ (long long)(int)sizeof(*((struct object_update_request *)0)->ourq_updates));
+ BUILD_BUG_ON(offsetof(struct object_update_request, ourq_updates) != sizeof(struct object_update_request));
BUILD_BUG_ON(UPDATE_REQUEST_MAGIC != 0xBDDE0002);
/* Checks for struct object_update_result */
(long long)(int)sizeof(((struct object_update_result *)0)->our_padding));
LASSERTF((int)offsetof(struct object_update_result, our_data) == 8, "found %lld\n",
(long long)(int)offsetof(struct object_update_result, our_data));
- LASSERTF((int)sizeof(((struct object_update_result *)0)->our_data) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct object_update_result *)0)->our_data));
+ LASSERTF((int)sizeof(*((struct object_update_result *)0)->our_data) == 4, "found %lld\n",
+ (long long)(int)sizeof(*((struct object_update_result *)0)->our_data));
+ BUILD_BUG_ON(offsetof(struct object_update_result, our_data) != sizeof(struct object_update_result));
/* Checks for struct object_update_reply */
LASSERTF((int)sizeof(struct object_update_reply) == 8, "found %lld\n",
(long long)(int)sizeof(((struct object_update_reply *)0)->ourp_padding));
LASSERTF((int)offsetof(struct object_update_reply, ourp_lens) == 8, "found %lld\n",
(long long)(int)offsetof(struct object_update_reply, ourp_lens));
- LASSERTF((int)sizeof(((struct object_update_reply *)0)->ourp_lens) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct object_update_reply *)0)->ourp_lens));
+ LASSERTF((int)sizeof(*((struct object_update_reply *)0)->ourp_lens) == 2, "found %lld\n",
+ (long long)(int)sizeof(*((struct object_update_reply *)0)->ourp_lens));
+ BUILD_BUG_ON(offsetof(struct object_update_reply, ourp_lens) != sizeof(struct object_update_reply));
BUILD_BUG_ON(UPDATE_REPLY_MAGIC != 0x00BD0002);
/* Checks for struct out_update_header */
(long long)(int)sizeof(((struct out_update_header *)0)->ouh_reply_size));
LASSERTF((int)offsetof(struct out_update_header, ouh_inline_data) == 16, "found %lld\n",
(long long)(int)offsetof(struct out_update_header, ouh_inline_data));
- LASSERTF((int)sizeof(((struct out_update_header *)0)->ouh_inline_data) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct out_update_header *)0)->ouh_inline_data));
+ LASSERTF((int)sizeof(*((struct out_update_header *)0)->ouh_inline_data) == 4, "found %lld\n",
+ (long long)(int)sizeof(*((struct out_update_header *)0)->ouh_inline_data));
+ BUILD_BUG_ON(offsetof(struct out_update_header, ouh_inline_data) != sizeof(struct out_update_header));
BUILD_BUG_ON(OUT_UPDATE_HEADER_MAGIC != 0xBDDF0001);
BUILD_BUG_ON(OUT_UPDATE_MAX_INLINE_SIZE != 4096);
#define STRINGIFY(a) #a
+#define CHECK_BUILD_TEST(a) \
+ printf(" BUILD_BUG_ON("#a");\n")
+
#define CHECK_CDEFINE(a) \
printf(" BUILD_BUG_ON("#a" != "STRINGIFY(a) ");\n")
CHECK_VALUE((int)sizeof(((struct s *)0)->m)); \
} while(0)
+#define CHECK_MEMBER_SIZEOF_ARRAY_ELEMENT(s, m) \
+do { \
+ CHECK_VALUE((int)sizeof(*((struct s *)0)->m)); \
+} while(0)
+
#define CHECK_MEMBER_SIZEOF_TYPEDEF(s, m) \
do { \
CHECK_VALUE((int)sizeof(((s *)0)->m)); \
} while(0)
-#define CHECK_MEMBER_IS_FLEXIBLE(s, m) \
+#define CHECK_MEMBER_IS_FLEXIBLE(s, m) \
+do { \
+ CHECK_MEMBER_OFFSET(s, m); \
+ CHECK_MEMBER_SIZEOF_ARRAY_ELEMENT(s, m); \
+ CHECK_BUILD_TEST(offsetof(struct s, m) != sizeof(struct s)); \
+} while (0)
+
+#define CHECK_MEMBER_IS_FLEXIBLE_OR_ZERO_LENGTH(s, m) \
do { \
CHECK_MEMBER_OFFSET(s, m); \
CHECK_BUILD_TEST(offsetof(struct s, m) != sizeof(struct s)); \
CHECK_MEMBER(lov_comp_md_v1, lcm_mirror_count);
CHECK_MEMBER(lov_comp_md_v1, lcm_padding1);
CHECK_MEMBER(lov_comp_md_v1, lcm_padding2);
- CHECK_MEMBER(lov_comp_md_v1, lcm_entries[0]);
+ CHECK_MEMBER_IS_FLEXIBLE(lov_comp_md_v1, lcm_entries);
CHECK_CDEFINE(LOV_MAGIC_COMP_V1);
CHECK_MEMBER(ldlm_request, lock_flags);
CHECK_MEMBER(ldlm_request, lock_count);
CHECK_MEMBER(ldlm_request, lock_desc);
- CHECK_MEMBER(ldlm_request, lock_handle);
+ CHECK_MEMBER_IS_FLEXIBLE(ldlm_request, lock_handle);
}
static void
CHECK_MEMBER(hsm_action_list, hal_flags);
CHECK_MEMBER(hsm_action_list, hal_archive_id);
CHECK_MEMBER(hsm_action_list, padding1);
- CHECK_MEMBER(hsm_action_list, hal_fsname);
+ CHECK_MEMBER_IS_FLEXIBLE(hsm_action_list, hal_fsname);
}
static void
CHECK_MEMBER(object_update_param, oup_len);
CHECK_MEMBER(object_update_param, oup_padding);
CHECK_MEMBER(object_update_param, oup_padding2);
- CHECK_MEMBER(object_update_param, oup_buf);
+ CHECK_MEMBER_IS_FLEXIBLE(object_update_param, oup_buf);
}
static void check_object_update(void)
CHECK_MEMBER(object_update, ou_padding1);
CHECK_MEMBER(object_update, ou_batchid);
CHECK_MEMBER(object_update, ou_fid);
- CHECK_MEMBER(object_update, ou_params);
+ CHECK_MEMBER_IS_FLEXIBLE(object_update, ou_params);
CHECK_CVALUE_X(UPDATE_FL_OST);
CHECK_CVALUE_X(UPDATE_FL_SYNC);
CHECK_MEMBER(object_update_request, ourq_magic);
CHECK_MEMBER(object_update_request, ourq_count);
CHECK_MEMBER(object_update_request, ourq_padding);
- CHECK_MEMBER(object_update_request, ourq_updates);
+ CHECK_MEMBER_IS_FLEXIBLE(object_update_request, ourq_updates);
CHECK_CDEFINE(UPDATE_REQUEST_MAGIC);
}
CHECK_MEMBER(object_update_result, our_rc);
CHECK_MEMBER(object_update_result, our_datalen);
CHECK_MEMBER(object_update_result, our_padding);
- CHECK_MEMBER(object_update_result, our_data);
+ CHECK_MEMBER_IS_FLEXIBLE(object_update_result, our_data);
}
static void check_object_update_reply(void)
CHECK_MEMBER(object_update_reply, ourp_magic);
CHECK_MEMBER(object_update_reply, ourp_count);
CHECK_MEMBER(object_update_reply, ourp_padding);
- CHECK_MEMBER(object_update_reply, ourp_lens);
+ CHECK_MEMBER_IS_FLEXIBLE(object_update_reply, ourp_lens);
CHECK_CDEFINE(UPDATE_REPLY_MAGIC);
}
CHECK_MEMBER(out_update_header, ouh_count);
CHECK_MEMBER(out_update_header, ouh_inline_length);
CHECK_MEMBER(out_update_header, ouh_reply_size);
- CHECK_MEMBER(out_update_header, ouh_inline_data);
+ CHECK_MEMBER_IS_FLEXIBLE(out_update_header, ouh_inline_data);
CHECK_CDEFINE(OUT_UPDATE_HEADER_MAGIC);
CHECK_CDEFINE(OUT_UPDATE_MAX_INLINE_SIZE);
OBD_MD_FLGID);
LASSERTF(OBD_MD_FLFLAGS == (0x00000800ULL), "found 0x%.16llxULL\n",
OBD_MD_FLFLAGS);
- LASSERTF(OBD_MD_DOM_SIZE == (0x00001000ULL), "found 0x%.16llxULL\n",
+ LASSERTF(OBD_MD_DOM_SIZE == (0X00001000ULL), "found 0x%.16llxULL\n",
OBD_MD_DOM_SIZE);
LASSERTF(OBD_MD_FLNLINK == (0x00002000ULL), "found 0x%.16llxULL\n",
OBD_MD_FLNLINK);
(long long)(int)sizeof(((struct lov_comp_md_v1 *)0)->lcm_padding2));
LASSERTF((int)offsetof(struct lov_comp_md_v1, lcm_entries[0]) == 32, "found %lld\n",
(long long)(int)offsetof(struct lov_comp_md_v1, lcm_entries[0]));
- LASSERTF((int)sizeof(((struct lov_comp_md_v1 *)0)->lcm_entries[0]) == 48, "found %lld\n",
- (long long)(int)sizeof(((struct lov_comp_md_v1 *)0)->lcm_entries[0]));
+ BUILD_BUG_ON(offsetof(struct lov_comp_md_v1, lcm_entries) != sizeof(struct lov_comp_md_v1));
BUILD_BUG_ON(LOV_MAGIC_COMP_V1 != (0x0BD60000 | 0x0BD0));
LASSERTF(LCM_FL_NONE == 0, "found %lld\n",
(long long)LCM_FL_NONE);
(long long)(int)sizeof(((struct ldlm_lock_desc *)0)->l_policy_data));
/* Checks for struct ldlm_request */
- LASSERTF((int)sizeof(struct ldlm_request) == 104, "found %lld\n",
+ LASSERTF((int)sizeof(struct ldlm_request) == 88, "found %lld\n",
(long long)(int)sizeof(struct ldlm_request));
LASSERTF((int)offsetof(struct ldlm_request, lock_flags) == 0, "found %lld\n",
(long long)(int)offsetof(struct ldlm_request, lock_flags));
(long long)(int)sizeof(((struct ldlm_request *)0)->lock_desc));
LASSERTF((int)offsetof(struct ldlm_request, lock_handle) == 88, "found %lld\n",
(long long)(int)offsetof(struct ldlm_request, lock_handle));
- LASSERTF((int)sizeof(((struct ldlm_request *)0)->lock_handle) == 16, "found %lld\n",
- (long long)(int)sizeof(((struct ldlm_request *)0)->lock_handle));
+ LASSERTF((int)sizeof(*((struct ldlm_request *)0)->lock_handle) == 8, "found %lld\n",
+ (long long)(int)sizeof(*((struct ldlm_request *)0)->lock_handle));
+ BUILD_BUG_ON(offsetof(struct ldlm_request, lock_handle) != sizeof(struct ldlm_request));
/* Checks for struct ldlm_reply */
LASSERTF((int)sizeof(struct ldlm_reply) == 112, "found %lld\n",
(long long)(int)sizeof(((struct fiemap *)0)->fm_reserved));
LASSERTF((int)offsetof(struct fiemap, fm_extents) == 32, "found %lld\n",
(long long)(int)offsetof(struct fiemap, fm_extents));
- LASSERTF((int)sizeof(((struct fiemap *)0)->fm_extents) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct fiemap *)0)->fm_extents));
+ BUILD_BUG_ON(offsetof(struct fiemap, fm_extents) != sizeof(struct fiemap));
BUILD_BUG_ON(FIEMAP_FLAG_SYNC != 0x00000001);
BUILD_BUG_ON(FIEMAP_FLAG_XATTR != 0x00000002);
BUILD_BUG_ON(FIEMAP_FLAG_DEVICE_ORDER != 0x40000000);
(long long)(int)sizeof(((struct hsm_action_list *)0)->padding1));
LASSERTF((int)offsetof(struct hsm_action_list, hal_fsname) == 32, "found %lld\n",
(long long)(int)offsetof(struct hsm_action_list, hal_fsname));
- LASSERTF((int)sizeof(((struct hsm_action_list *)0)->hal_fsname) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct hsm_action_list *)0)->hal_fsname));
+ BUILD_BUG_ON(offsetof(struct hsm_action_list, hal_fsname) != sizeof(struct hsm_action_list));
/* Checks for struct hsm_progress */
LASSERTF((int)sizeof(struct hsm_progress) == 48, "found %lld\n",
(long long)(int)sizeof(((struct object_update_param *)0)->oup_padding2));
LASSERTF((int)offsetof(struct object_update_param, oup_buf) == 8, "found %lld\n",
(long long)(int)offsetof(struct object_update_param, oup_buf));
- LASSERTF((int)sizeof(((struct object_update_param *)0)->oup_buf) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct object_update_param *)0)->oup_buf));
+ BUILD_BUG_ON(offsetof(struct object_update_param, oup_buf) != sizeof(struct object_update_param));
/* Checks for struct object_update */
LASSERTF((int)sizeof(struct object_update) == 40, "found %lld\n",
(long long)(int)sizeof(((struct object_update *)0)->ou_fid));
LASSERTF((int)offsetof(struct object_update, ou_params) == 40, "found %lld\n",
(long long)(int)offsetof(struct object_update, ou_params));
- LASSERTF((int)sizeof(((struct object_update *)0)->ou_params) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct object_update *)0)->ou_params));
+ BUILD_BUG_ON(offsetof(struct object_update, ou_params) != sizeof(struct object_update));
BUILD_BUG_ON(UPDATE_FL_OST != 0x00000001);
BUILD_BUG_ON(UPDATE_FL_SYNC != 0x00000002);
BUILD_BUG_ON(UPDATE_FL_COMMITTED != 0x00000004);
(long long)(int)sizeof(((struct object_update_request *)0)->ourq_padding));
LASSERTF((int)offsetof(struct object_update_request, ourq_updates) == 8, "found %lld\n",
(long long)(int)offsetof(struct object_update_request, ourq_updates));
- LASSERTF((int)sizeof(((struct object_update_request *)0)->ourq_updates) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct object_update_request *)0)->ourq_updates));
+ BUILD_BUG_ON(offsetof(struct object_update_request, ourq_updates) != sizeof(struct object_update_request));
BUILD_BUG_ON(UPDATE_REQUEST_MAGIC != 0xBDDE0002);
/* Checks for struct object_update_result */
(long long)(int)sizeof(((struct object_update_result *)0)->our_padding));
LASSERTF((int)offsetof(struct object_update_result, our_data) == 8, "found %lld\n",
(long long)(int)offsetof(struct object_update_result, our_data));
- LASSERTF((int)sizeof(((struct object_update_result *)0)->our_data) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct object_update_result *)0)->our_data));
+ BUILD_BUG_ON(offsetof(struct object_update_result, our_data) != sizeof(struct object_update_result));
/* Checks for struct object_update_reply */
LASSERTF((int)sizeof(struct object_update_reply) == 8, "found %lld\n",
(long long)(int)sizeof(((struct object_update_reply *)0)->ourp_padding));
LASSERTF((int)offsetof(struct object_update_reply, ourp_lens) == 8, "found %lld\n",
(long long)(int)offsetof(struct object_update_reply, ourp_lens));
- LASSERTF((int)sizeof(((struct object_update_reply *)0)->ourp_lens) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct object_update_reply *)0)->ourp_lens));
+ BUILD_BUG_ON(offsetof(struct object_update_reply, ourp_lens) != sizeof(struct object_update_reply));
BUILD_BUG_ON(UPDATE_REPLY_MAGIC != 0x00BD0002);
/* Checks for struct out_update_header */
(long long)(int)sizeof(((struct out_update_header *)0)->ouh_reply_size));
LASSERTF((int)offsetof(struct out_update_header, ouh_inline_data) == 16, "found %lld\n",
(long long)(int)offsetof(struct out_update_header, ouh_inline_data));
- LASSERTF((int)sizeof(((struct out_update_header *)0)->ouh_inline_data) == 0, "found %lld\n",
- (long long)(int)sizeof(((struct out_update_header *)0)->ouh_inline_data));
+ BUILD_BUG_ON(offsetof(struct out_update_header, ouh_inline_data) != sizeof(struct out_update_header));
BUILD_BUG_ON(OUT_UPDATE_HEADER_MAGIC != 0xBDDF0001);
BUILD_BUG_ON(OUT_UPDATE_MAX_INLINE_SIZE != 4096);