Whamcloud - gitweb
LU-5030 libcfs: create cfs_get_paths() function
[fs/lustre-release.git] / libcfs / include / libcfs / libcfs_cpu.h
index 98832fd..380be11 100644 (file)
@@ -23,7 +23,7 @@
 /*
  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  *
- * Copyright (c) 2012, 2014, Intel Corporation.
+ * Copyright (c) 2012, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -261,7 +261,8 @@ struct cfs_percpt_lock {
  * create a cpu-partition lock based on CPU partition table \a cptab,
  * each private lock has extra \a psize bytes padding data
  */
-struct cfs_percpt_lock *cfs_percpt_lock_alloc(struct cfs_cpt_table *cptab);
+struct cfs_percpt_lock *cfs_percpt_lock_create(struct cfs_cpt_table *cptab,
+                                              struct lock_class_key *keys);
 /* destroy a cpu-partition lock */
 void cfs_percpt_lock_free(struct cfs_percpt_lock *pcl);
 
@@ -270,6 +271,21 @@ void cfs_percpt_lock(struct cfs_percpt_lock *pcl, int index);
 /* unlock private lock \a index of \a pcl */
 void cfs_percpt_unlock(struct cfs_percpt_lock *pcl, int index);
 
+#define CFS_PERCPT_LOCK_KEYS   256
+
+/* NB: don't allocate keys dynamically, lockdep needs them to be in ".data" */
+#define cfs_percpt_lock_alloc(cptab)                                   \
+({                                                                     \
+       static struct lock_class_key  ___keys[CFS_PERCPT_LOCK_KEYS];    \
+       struct cfs_percpt_lock       *___lk;                            \
+                                                                       \
+       if (cfs_cpt_number(cptab) > CFS_PERCPT_LOCK_KEYS)               \
+               ___lk = cfs_percpt_lock_create(cptab, NULL);            \
+       else                                                            \
+               ___lk = cfs_percpt_lock_create(cptab, ___keys);         \
+       ___lk;                                                          \
+})
+
 /**
  * allocate \a nr_bytes of physical memory from a contiguous region with the
  * properties of \a flags which are bound to the partition id \a cpt. This