Whamcloud - gitweb
LU-5855 lfsck: misc fixes for zfs-based backend
[fs/lustre-release.git] / lustre / include / obd_support.h
index b9ec568..0bdfc4a 100644 (file)
 #ifndef _OBD_SUPPORT
 #define _OBD_SUPPORT
 
+#ifndef __KERNEL__
+# error Userspace should not include obd_support.h.
+#endif /* !__KERNEL__ */
+
+#include <linux/atomic.h>
+#include <linux/highmem.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+
 #include <libcfs/libcfs.h>
-#include <lvfs.h>
 #include <lprocfs_status.h>
-
-#if defined(__linux__)
-#include <linux/obd_support.h>
-#elif defined(__APPLE__)
-#include <darwin/obd_support.h>
-#elif defined(__WINNT__)
-#include <winnt/obd_support.h>
-#else
-#error Unsupported operating system.
-#endif
+#include <lustre_handles.h>
 
 /* global variables */
 extern struct lprocfs_stats *obd_memory;
@@ -68,15 +67,15 @@ extern unsigned int obd_timeout;          /* seconds */
 extern unsigned int ldlm_timeout;         /* seconds */
 extern unsigned int obd_timeout_set;
 extern unsigned int ldlm_timeout_set;
+extern unsigned int bulk_timeout;
 extern unsigned int at_min;
 extern unsigned int at_max;
 extern unsigned int at_history;
 extern int at_early_margin;
 extern int at_extra;
-extern unsigned int obd_sync_filter;
-extern unsigned int obd_max_dirty_pages;
-extern cfs_atomic_t obd_dirty_pages;
-extern cfs_atomic_t obd_dirty_transit_pages;
+extern unsigned long obd_max_dirty_pages;
+extern atomic_long_t obd_dirty_pages;
+extern atomic_long_t obd_dirty_transit_pages;
 extern unsigned int obd_alloc_fail_rate;
 extern char obd_jobid_var[];
 
@@ -242,6 +241,11 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
 #define OBD_FAIL_MDS_SWAP_LAYOUTS_NET          0x14f
 #define OBD_FAIL_MDS_HSM_ACTION_NET            0x150
 #define OBD_FAIL_MDS_CHANGELOG_INIT            0x151
+#define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS          0x152
+#define OBD_FAIL_MDS_RENAME              0x153
+#define OBD_FAIL_MDS_RENAME2             0x154
+#define OBD_FAIL_MDS_RENAME3             0x155
+#define OBD_FAIL_MDS_RENAME4             0x156
 
 /* layout lock */
 #define OBD_FAIL_MDS_NO_LL_GETATTR      0x170
@@ -265,6 +269,7 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
 #define OBD_FAIL_OSD_FID_MAPPING                       0x193
 #define OBD_FAIL_OSD_LMA_INCOMPAT                      0x194
 #define OBD_FAIL_OSD_COMPAT_INVALID_ENTRY              0x195
+#define OBD_FAIL_OSD_COMPAT_NO_ENTRY                   0x196
 
 #define OBD_FAIL_OST                     0x200
 #define OBD_FAIL_OST_CONNECT_NET         0x201
@@ -310,6 +315,8 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
 #define OBD_FAIL_OST_ENOINO              0x229
 #define OBD_FAIL_OST_DQACQ_NET           0x230
 #define OBD_FAIL_OST_STATFS_EINPROGRESS  0x231
+#define OBD_FAIL_OST_SET_INFO_NET        0x232
+#define OBD_FAIL_OST_NODESTROY          0x233
 
 #define OBD_FAIL_LDLM                    0x300
 #define OBD_FAIL_LDLM_NAMESPACE_NEW      0x301
@@ -340,6 +347,12 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
 #define OBD_FAIL_LDLM_AGL_DELAY          0x31a
 #define OBD_FAIL_LDLM_AGL_NOLOCK         0x31b
 #define OBD_FAIL_LDLM_OST_LVB           0x31c
+#define OBD_FAIL_LDLM_ENQUEUE_HANG      0x31d
+#define OBD_FAIL_LDLM_PAUSE_CANCEL2      0x31f
+#define OBD_FAIL_LDLM_CP_CB_WAIT2        0x320
+#define OBD_FAIL_LDLM_CP_CB_WAIT3        0x321
+#define OBD_FAIL_LDLM_CP_CB_WAIT4        0x322
+#define OBD_FAIL_LDLM_CP_CB_WAIT5        0x323
 
 /* LOCKLESS IO */
 #define OBD_FAIL_LDLM_SET_CONTENTION     0x385
@@ -411,6 +424,9 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
 #define OBD_FAIL_TGT_LAST_REPLAY         0x710
 #define OBD_FAIL_TGT_CLIENT_ADD          0x711
 #define OBD_FAIL_TGT_RCVG_FLAG           0x712
+#define OBD_FAIL_TGT_DELAY_CONDITIONAL  0x713
+#define OBD_FAIL_TGT_REPLAY_DELAY2       0x714
+#define OBD_FAIL_TGT_REPLAY_RECONNECT   0x715
 
 #define OBD_FAIL_MDC_REVALIDATE_PAUSE    0x800
 #define OBD_FAIL_MDC_ENQUEUE_PAUSE       0x801
@@ -448,6 +464,7 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
 
 #define OBD_FAIL_FLD                     0x1100
 #define OBD_FAIL_FLD_QUERY_NET           0x1101
+#define OBD_FAIL_FLD_READ_NET           0x1102
 
 #define OBD_FAIL_SEC_CTX                 0x1200
 #define OBD_FAIL_SEC_CTX_INIT_NET        0x1201
@@ -473,6 +490,7 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
 #define OBD_FAIL_LOCK_STATE_WAIT_INTR               0x1402
 #define OBD_FAIL_LOV_INIT                          0x1403
 #define OBD_FAIL_GLIMPSE_DELAY                     0x1404
+#define OBD_FAIL_LLITE_XATTR_ENOMEM                0x1405
 
 #define OBD_FAIL_FID_INDIR     0x1501
 #define OBD_FAIL_FID_INLMA     0x1502
@@ -492,11 +510,79 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
 #define OBD_FAIL_LFSCK_CRASH           0x160a
 #define OBD_FAIL_LFSCK_NO_AUTO         0x160b
 #define OBD_FAIL_LFSCK_NO_DOUBLESCAN   0x160c
+#define OBD_FAIL_LFSCK_SKIP_LASTID     0x160d
+#define OBD_FAIL_LFSCK_DELAY4          0x160e
+#define OBD_FAIL_LFSCK_BAD_LMMOI       0x160f
+#define OBD_FAIL_LFSCK_DANGLING        0x1610
+#define OBD_FAIL_LFSCK_UNMATCHED_PAIR1 0x1611
+#define OBD_FAIL_LFSCK_UNMATCHED_PAIR2 0x1612
+#define OBD_FAIL_LFSCK_BAD_OWNER       0x1613
+#define OBD_FAIL_LFSCK_MULTIPLE_REF    0x1614
+#define OBD_FAIL_LFSCK_LOST_STRIPE     0x1615
+#define OBD_FAIL_LFSCK_LOST_MDTOBJ     0x1616
+#define OBD_FAIL_LFSCK_NOPFID          0x1617
+#define OBD_FAIL_LFSCK_CHANGE_STRIPE   0x1618
+#define OBD_FAIL_LFSCK_INVALID_PFID    0x1619
+#define OBD_FAIL_LFSCK_LOST_SPEOBJ     0x161a
+#define OBD_FAIL_LFSCK_DELAY5          0x161b
+#define OBD_FAIL_LFSCK_BAD_NETWORK     0x161c
+#define OBD_FAIL_LFSCK_NO_LINKEA       0x161d
+#define OBD_FAIL_LFSCK_BAD_PARENT      0x161e
+#define OBD_FAIL_LFSCK_DANGLING2       0x1620
+#define OBD_FAIL_LFSCK_DANGLING3       0x1621
+#define OBD_FAIL_LFSCK_MUL_REF         0x1622
+#define OBD_FAIL_LFSCK_BAD_TYPE                0x1623
+#define OBD_FAIL_LFSCK_NO_NAMEENTRY    0x1624
+#define OBD_FAIL_LFSCK_MORE_NLINK      0x1625
+#define OBD_FAIL_LFSCK_LESS_NLINK      0x1626
+#define OBD_FAIL_LFSCK_LINKEA_OVERFLOW 0x1627
+#define OBD_FAIL_LFSCK_BAD_NAME_HASH   0x1628
+#define OBD_FAIL_LFSCK_LOST_MASTER_LMV 0x1629
+#define OBD_FAIL_LFSCK_LOST_SLAVE_LMV  0x162a
+#define OBD_FAIL_LFSCK_BAD_SLAVE_LMV   0x162b
+#define OBD_FAIL_LFSCK_BAD_SLAVE_NAME  0x162c
+
+#define OBD_FAIL_LFSCK_NOTIFY_NET      0x16f0
+#define OBD_FAIL_LFSCK_QUERY_NET       0x16f1
 
 /* UPDATE */
-#define OBD_FAIL_UPDATE_OBJ_NET                        0x1700
-#define OBD_FAIL_UPDATE_OBJ_NET_REP            0x1701
-
+#define OBD_FAIL_OUT_UPDATE_NET                0x1700
+#define OBD_FAIL_OUT_UPDATE_NET_REP    0x1701
+
+/* MIGRATE */
+#define OBD_FAIL_MIGRATE_NET_REP               0x1800
+#define OBD_FAIL_MIGRATE_ENTRIES               0x1801
+#define OBD_FAIL_MIGRATE_LINKEA                        0x1802
+
+/* LMV */
+#define OBD_FAIL_UNKNOWN_LMV_STRIPE            0x1901
+
+/* DT */
+#define OBD_FAIL_DT_DECLARE_ATTR_GET           0x2000
+#define OBD_FAIL_DT_ATTR_GET                   0x2001
+#define OBD_FAIL_DT_DECLARE_ATTR_SET           0x2002
+#define OBD_FAIL_DT_ATTR_SET                   0x2003
+#define OBD_FAIL_DT_DECLARE_XATTR_GET          0x2004
+#define OBD_FAIL_DT_XATTR_GET                  0x2005
+#define OBD_FAIL_DT_DECLARE_XATTR_SET          0x2006
+#define OBD_FAIL_DT_XATTR_SET                  0x2007
+#define OBD_FAIL_DT_DECLARE_XATTR_DEL          0x2008
+#define OBD_FAIL_DT_XATTR_DEL                  0x2009
+#define OBD_FAIL_DT_XATTR_LIST                 0x200a
+#define OBD_FAIL_DT_DECLARE_CREATE             0x200b
+#define OBD_FAIL_DT_CREATE                     0x200c
+#define OBD_FAIL_DT_DECLARE_DESTROY            0x200d
+#define OBD_FAIL_DT_DESTROY                    0x200e
+#define OBD_FAIL_DT_INDEX_TRY                  0x200f
+#define OBD_FAIL_DT_DECLARE_REF_ADD            0x2010
+#define OBD_FAIL_DT_REF_ADD                    0x2011
+#define OBD_FAIL_DT_DECLARE_REF_DEL            0x2012
+#define OBD_FAIL_DT_REF_DEL                    0x2013
+#define OBD_FAIL_DT_DECLARE_INSERT             0x2014
+#define OBD_FAIL_DT_INSERT                     0x2015
+#define OBD_FAIL_DT_DECLARE_DELETE             0x2016
+#define OBD_FAIL_DT_DELETE                     0x2017
+#define OBD_FAIL_DT_LOOKUP                     0x2018
 
 /* Assign references to moved code to reduce code changes */
 #define OBD_FAIL_PRECHECK(id)                   CFS_FAIL_PRECHECK(id)
@@ -512,7 +598,7 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
 #define OBD_FAIL_ONCE                           CFS_FAIL_ONCE
 #define OBD_FAILED                              CFS_FAILED
 
-extern cfs_atomic_t libcfs_kmemory;
+extern atomic_t libcfs_kmemory;
 
 #ifdef LPROCFS
 #define obd_memory_add(size)                                                  \
@@ -536,7 +622,7 @@ extern void obd_update_maxusage(void);
 extern __u64 obd_memory_max(void);
 extern __u64 obd_pages_max(void);
 
-#else
+#else /* LPROCFS */
 
 extern __u64 obd_alloc;
 extern __u64 obd_pages;
@@ -574,7 +660,7 @@ static inline void obd_pages_sub(int order)
 #define obd_memory_max() (obd_max_alloc)
 #define obd_pages_max() (obd_max_pages)
 
-#endif
+#endif /* !LPROCFS */
 
 #define OBD_DEBUG_MEMUSAGE (1)
 
@@ -608,22 +694,6 @@ static inline void obd_pages_sub(int order)
 #define OBD_ALLOC_FAIL_MASK ((1 << OBD_ALLOC_FAIL_BITS) - 1)
 #define OBD_ALLOC_FAIL_MULT (OBD_ALLOC_FAIL_MASK / 100)
 
-#if defined(LUSTRE_UTILS) /* this version is for utils only */
-#define __OBD_MALLOC_VERBOSE(ptr, cptab, cpt, size, flags)                   \
-do {                                                                         \
-       (ptr) = (cptab) == NULL ?                                             \
-               kmalloc(size, flags | __GFP_ZERO) :                           \
-               cfs_cpt_malloc(cptab, cpt, size, flags | __GFP_ZERO);         \
-       if (unlikely((ptr) == NULL)) {                                        \
-               CERROR("kmalloc of '" #ptr "' (%d bytes) failed at %s:%d\n",  \
-                      (int)(size), __FILE__, __LINE__);                      \
-       } else {                                                              \
-               CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %d at %p\n",          \
-                      (int)(size), ptr);                                     \
-       }                                                                     \
-} while (0)
-
-#else /* this version is for the kernel and liblustre */
 #define OBD_FREE_RTN0(ptr)                                                    \
 ({                                                                            \
        kfree(ptr);                                                        \
@@ -644,13 +714,12 @@ do {                                                                            \
                 OBD_ALLOC_POST(ptr, size, "kmalloced");                       \
         }                                                                     \
 } while (0)
-#endif
 
 #define OBD_ALLOC_GFP(ptr, size, gfp_mask)                                   \
        __OBD_MALLOC_VERBOSE(ptr, NULL, 0, size, gfp_mask)
 
-#define OBD_ALLOC(ptr, size) OBD_ALLOC_GFP(ptr, size, __GFP_IO)
-#define OBD_ALLOC_WAIT(ptr, size) OBD_ALLOC_GFP(ptr, size, GFP_IOFS)
+#define OBD_ALLOC(ptr, size) OBD_ALLOC_GFP(ptr, size, GFP_NOFS)
+#define OBD_ALLOC_WAIT(ptr, size) OBD_ALLOC_GFP(ptr, size, GFP_KERNEL)
 #define OBD_ALLOC_PTR(ptr) OBD_ALLOC(ptr, sizeof *(ptr))
 #define OBD_ALLOC_PTR_WAIT(ptr) OBD_ALLOC_WAIT(ptr, sizeof *(ptr))
 
@@ -658,33 +727,35 @@ do {                                                                            \
        __OBD_MALLOC_VERBOSE(ptr, cptab, cpt, size, gfp_mask)
 
 #define OBD_CPT_ALLOC(ptr, cptab, cpt, size)                                 \
-       OBD_CPT_ALLOC_GFP(ptr, cptab, cpt, size, __GFP_IO)
+       OBD_CPT_ALLOC_GFP(ptr, cptab, cpt, size, GFP_NOFS)
 
 #define OBD_CPT_ALLOC_PTR(ptr, cptab, cpt)                                   \
        OBD_CPT_ALLOC(ptr, cptab, cpt, sizeof *(ptr))
 
-# define __OBD_VMALLOC_VEROBSE(ptr, cptab, cpt, size)                        \
+/* Direct use of __vmalloc() allows for protection flag specification
+ * (and particularly to not set __GFP_FS, which is likely to cause some
+ * deadlock situations in our code).
+ */
+#define __OBD_VMALLOC_VERBOSE(ptr, cptab, cpt, size)                         \
 do {                                                                         \
        (ptr) = cptab == NULL ?                                               \
-               vmalloc(size) :                                       \
-               cfs_cpt_vmalloc(cptab, cpt, size);                            \
-        if (unlikely((ptr) == NULL)) {                                        \
-                CERROR("vmalloc of '" #ptr "' (%d bytes) failed\n",           \
-                       (int)(size));                                          \
-                CERROR(LPU64" total bytes allocated by Lustre, %d by LNET\n", \
-                       obd_memory_sum(), cfs_atomic_read(&libcfs_kmemory));   \
-        } else {                                                              \
-               memset(ptr, 0, size);                                         \
-                OBD_ALLOC_POST(ptr, size, "vmalloced");                       \
-        }                                                                     \
+               __vmalloc(size, GFP_NOFS | __GFP_HIGHMEM | __GFP_ZERO,        \
+                         PAGE_KERNEL) :                                      \
+               cfs_cpt_vzalloc(cptab, cpt, size);                            \
+       if (unlikely((ptr) == NULL)) {                                        \
+               CERROR("vmalloc of '" #ptr "' (%d bytes) failed\n",           \
+                      (int)(size));                                          \
+               CERROR(LPU64" total bytes allocated by Lustre, %d by LNET\n", \
+                      obd_memory_sum(), atomic_read(&libcfs_kmemory));       \
+       } else {                                                              \
+               OBD_ALLOC_POST(ptr, size, "vmalloced");                       \
+       }                                                                     \
 } while(0)
 
-# define OBD_VMALLOC(ptr, size)                                                      \
-        __OBD_VMALLOC_VEROBSE(ptr, NULL, 0, size)
-# define OBD_CPT_VMALLOC(ptr, cptab, cpt, size)                                      \
-        __OBD_VMALLOC_VEROBSE(ptr, cptab, cpt, size)
-
-#ifdef __KERNEL__
+#define OBD_VMALLOC(ptr, size)                                               \
+        __OBD_VMALLOC_VERBOSE(ptr, NULL, 0, size)
+#define OBD_CPT_VMALLOC(ptr, cptab, cpt, size)                               \
+        __OBD_VMALLOC_VERBOSE(ptr, cptab, cpt, size)
 
 /* Allocations above this size are considered too big and could not be done
  * atomically.
@@ -719,17 +790,6 @@ do {                                                                          \
                 OBD_FREE(ptr, size);                                          \
 } while (0)
 
-#else /* !__KERNEL__ */
-
-#define OBD_ALLOC_LARGE(ptr, size)                                           \
-       OBD_ALLOC(ptr, size)
-#define OBD_CPT_ALLOC_LARGE(ptr, cptab, cpt, size)                           \
-       OBD_ALLOC(ptr, size)
-#define OBD_FREE_LARGE(ptr, size)                                            \
-       OBD_FREE(ptr, size)
-
-#endif /* __KERNEL__ */
-
 #ifdef CONFIG_DEBUG_SLAB
 #define POISON(ptr, c, s) do {} while (0)
 #define POISON_PTR(ptr)  ((void)0)
@@ -745,7 +805,6 @@ do {                                                                          \
 #define POISON_PAGE(page, val) do { } while (0)
 #endif
 
-#ifdef __KERNEL__
 #define OBD_FREE(ptr, size)                                                   \
 do {                                                                          \
         OBD_FREE_PRE(ptr, size, "kfreed");                                    \
@@ -765,11 +824,6 @@ do {                                                                             \
        POISON_PTR(ptr);                                                      \
 } while(0)
 
-#else
-#define OBD_FREE(ptr, size) ((void)(size), free((ptr)))
-#define OBD_FREE_RCU(ptr, size, handle) (OBD_FREE(ptr, size))
-#endif /* ifdef __KERNEL__ */
-
 #define OBD_VFREE(ptr, size)                           \
        do {                                            \
                OBD_FREE_PRE(ptr, size, "vfreed");      \
@@ -789,7 +843,7 @@ do {                                                                              \
 
 #define __OBD_SLAB_ALLOC_VERBOSE(ptr, slab, cptab, cpt, size, type)          \
 do {                                                                         \
-       LASSERT(ergo((type) != GFP_ATOMIC, !cfs_in_interrupt()));             \
+       LASSERT(ergo((type) != GFP_ATOMIC, !in_interrupt()));         \
        (ptr) = (cptab) == NULL ?                                             \
                kmem_cache_alloc(slab, type | __GFP_ZERO) :                   \
                cfs_mem_cache_cpt_alloc(slab, cptab, cpt, type | __GFP_ZERO); \
@@ -817,10 +871,10 @@ do {                                                                          \
 } while(0)
 
 #define OBD_SLAB_ALLOC(ptr, slab, size)                                              \
-       OBD_SLAB_ALLOC_GFP(ptr, slab, size, __GFP_IO)
+       OBD_SLAB_ALLOC_GFP(ptr, slab, size, GFP_NOFS)
 
 #define OBD_SLAB_CPT_ALLOC(ptr, slab, cptab, cpt, size)                              \
-       OBD_SLAB_CPT_ALLOC_GFP(ptr, slab, cptab, cpt, size, __GFP_IO)
+       OBD_SLAB_CPT_ALLOC_GFP(ptr, slab, cptab, cpt, size, GFP_NOFS)
 
 #define OBD_SLAB_ALLOC_PTR(ptr, slab)                                        \
        OBD_SLAB_ALLOC(ptr, slab, sizeof *(ptr))
@@ -854,11 +908,11 @@ do {                                                                            \
                        "("LPU64" bytes) allocated by Lustre, "                \
                        "%d total bytes by LNET\n",                            \
                        obd_memory_sum(),                                      \
-                      obd_pages_sum() << PAGE_CACHE_SHIFT,                     \
-                       obd_pages_sum(),                                       \
-                       cfs_atomic_read(&libcfs_kmemory));                     \
-        } else {                                                              \
-                obd_pages_add(0);                                             \
+                      obd_pages_sum() << PAGE_CACHE_SHIFT,                   \
+                      obd_pages_sum(),                                       \
+                      atomic_read(&libcfs_kmemory));                         \
+       } else {                                                              \
+               obd_pages_add(0);                                             \
                 CDEBUG(D_MALLOC, "alloc_pages '" #ptr "': %d page(s) / "      \
                        LPU64" bytes at %p.\n",                                \
                        (int)1,                                                \