Whamcloud - gitweb
LU-6147 lfsck: NOT purge object by OI scrub
[fs/lustre-release.git] / lustre / obdclass / lu_object.c
index cc43d7c..3e17c05 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2013, Intel Corporation.
+ * Copyright (c) 2011, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #define DEBUG_SUBSYSTEM S_CLASS
 
 #include <libcfs/libcfs.h>
-
-#ifdef __KERNEL__
-# include <linux/module.h>
-#endif
-
-/* hash_long() */
-#include <libcfs/libcfs_hash.h>
+#include <linux/module.h>
+#include <libcfs/libcfs_hash.h> /* hash_long() */
 #include <obd_class.h>
 #include <obd_support.h>
 #include <lustre_disk.h>
@@ -156,7 +151,8 @@ void lu_object_put(const struct lu_env *env, struct lu_object *o)
                         o->lo_ops->loo_object_release(env, o);
         }
 
-        if (!lu_object_is_dying(top)) {
+       if (!lu_object_is_dying(top) &&
+           (lu_object_exists(orig) || lu_object_is_cl(orig))) {
                LASSERT(list_empty(&top->loh_lru));
                list_add_tail(&top->loh_lru, &bkt->lsb_lru);
                 cfs_hash_bd_unlock(site->ls_obj_hash, &bd, 1);
@@ -348,11 +344,11 @@ int lu_site_purge(const struct lu_env *env, struct lu_site *s, int nr)
         cfs_hash_bd_t            bd;
         cfs_hash_bd_t            bd2;
        struct list_head         dispose;
-        int                      did_sth;
-        int                      start;
+       int                      did_sth;
+       unsigned int             start;
         int                      count;
         int                      bnr;
-        int                      i;
+       unsigned int             i;
 
        if (OBD_FAIL_CHECK(OBD_FAIL_OBD_NO_LRU))
                RETURN(0);
@@ -363,7 +359,7 @@ int lu_site_purge(const struct lu_env *env, struct lu_site *s, int nr)
          * the dispose list, removing them from LRU and hash table.
          */
         start = s->ls_purge_start;
-        bnr = (nr == ~0) ? -1 : nr / CFS_HASH_NBKT(s->ls_obj_hash) + 1;
+       bnr = (nr == ~0) ? -1 : nr / (int)CFS_HASH_NBKT(s->ls_obj_hash) + 1;
  again:
        /*
         * It doesn't make any sense to make purge threads parallel, that can
@@ -466,7 +462,7 @@ LU_KEY_INIT_FINI(lu_global, struct lu_cdebug_data);
  * Key, holding temporary buffer. This key is registered very early by
  * lu_global_init().
  */
-struct lu_context_key lu_global_key = {
+static struct lu_context_key lu_global_key = {
        .lct_tags = LCT_MD_THREAD | LCT_DT_THREAD |
                    LCT_MG_THREAD | LCT_CL_THREAD | LCT_LOCAL,
        .lct_init = lu_global_key_init,
@@ -610,36 +606,14 @@ static struct lu_object *htable_lookup(struct lu_site *s,
          * drained), and moreover, lookup has to wait until object is freed.
          */
 
-       init_waitqueue_entry_current(waiter);
-       add_wait_queue(&bkt->lsb_marche_funebre, waiter);
-       set_current_state(TASK_UNINTERRUPTIBLE);
-       lprocfs_counter_incr(s->ls_stats, LU_SS_CACHE_DEATH_RACE);
-       return ERR_PTR(-EAGAIN);
-}
-
-static struct lu_object *htable_lookup_nowait(struct lu_site *s,
-                                             cfs_hash_bd_t *bd,
-                                             const struct lu_fid *f)
-{
-       struct hlist_node       *hnode;
-       struct lu_object_header *h;
-
-       /* cfs_hash_bd_peek_locked is a somehow "internal" function
-        * of cfs_hash, it doesn't add refcount on object. */
-       hnode = cfs_hash_bd_peek_locked(s->ls_obj_hash, bd, (void *)f);
-       if (hnode == NULL) {
-               lprocfs_counter_incr(s->ls_stats, LU_SS_CACHE_MISS);
-               return ERR_PTR(-ENOENT);
+       if (likely(waiter != NULL)) {
+               init_waitqueue_entry_current(waiter);
+               add_wait_queue(&bkt->lsb_marche_funebre, waiter);
+               set_current_state(TASK_UNINTERRUPTIBLE);
+               lprocfs_counter_incr(s->ls_stats, LU_SS_CACHE_DEATH_RACE);
        }
 
-       h = container_of0(hnode, struct lu_object_header, loh_hash);
-       if (unlikely(lu_object_is_dying(h)))
-               return ERR_PTR(-ENOENT);
-
-       cfs_hash_get(s->ls_obj_hash, hnode);
-       lprocfs_counter_incr(s->ls_stats, LU_SS_CACHE_HIT);
-       list_del_init(&h->loh_lru);
-       return lu_object_top(h);
+       return ERR_PTR(-EAGAIN);
 }
 
 /**
@@ -798,6 +772,9 @@ struct lu_object *lu_object_find_at(const struct lu_env *env,
        struct lu_object        *obj;
        wait_queue_t           wait;
 
+       if (conf != NULL && conf->loc_flags & LOC_F_NOWAIT)
+               return lu_object_find_try(env, dev, f, conf, NULL);
+
        while (1) {
                obj = lu_object_find_try(env, dev, f, conf, &wait);
                if (obj != ERR_PTR(-EAGAIN))
@@ -814,30 +791,6 @@ struct lu_object *lu_object_find_at(const struct lu_env *env,
 EXPORT_SYMBOL(lu_object_find_at);
 
 /**
- * Try to find the object in cache without waiting for the dead object
- * to be released nor allocating object if no cached one was found.
- *
- * The found object will be set as LU_OBJECT_HEARD_BANSHEE for purging.
- */
-void lu_object_purge(const struct lu_env *env, struct lu_device *dev,
-                    const struct lu_fid *f)
-{
-       struct lu_site          *s  = dev->ld_site;
-       cfs_hash_t              *hs = s->ls_obj_hash;
-       cfs_hash_bd_t            bd;
-       struct lu_object        *o;
-
-       cfs_hash_bd_get_and_lock(hs, f, &bd, 1);
-       o = htable_lookup_nowait(s, &bd, f);
-       cfs_hash_bd_unlock(hs, &bd, 1);
-       if (!IS_ERR(o)) {
-               set_bit(LU_OBJECT_HEARD_BANSHEE, &o->lo_header->loh_flags);
-               lu_object_put(env, o);
-       }
-}
-EXPORT_SYMBOL(lu_object_purge);
-
-/**
  * Find object with given fid, and return its slice belonging to given device.
  */
 struct lu_object *lu_object_find_slice(const struct lu_env *env,
@@ -845,17 +798,20 @@ struct lu_object *lu_object_find_slice(const struct lu_env *env,
                                        const struct lu_fid *f,
                                        const struct lu_object_conf *conf)
 {
-        struct lu_object *top;
-        struct lu_object *obj;
+       struct lu_object *top;
+       struct lu_object *obj;
+
+       top = lu_object_find(env, dev, f, conf);
+       if (IS_ERR(top))
+               return top;
+
+       obj = lu_object_locate(top->lo_header, dev->ld_type);
+       if (unlikely(obj == NULL)) {
+               lu_object_put(env, top);
+               obj = ERR_PTR(-ENOENT);
+       }
 
-        top = lu_object_find(env, dev, f, conf);
-        if (!IS_ERR(top)) {
-                obj = lu_object_locate(top->lo_header, dev->ld_type);
-                if (obj == NULL)
-                        lu_object_put(env, top);
-        } else
-                obj = top;
-        return obj;
+       return obj;
 }
 EXPORT_SYMBOL(lu_object_find_slice);
 
@@ -950,10 +906,10 @@ EXPORT_SYMBOL(lu_site_print);
 /**
  * Return desired hash table order.
  */
-static int lu_htable_order(struct lu_device *top)
+static unsigned long lu_htable_order(struct lu_device *top)
 {
-        unsigned long cache_size;
-        int bits;
+       unsigned long cache_size;
+       unsigned long bits;
 
        /*
         * For ZFS based OSDs the cache should be disabled by default.  This
@@ -1060,7 +1016,7 @@ static void lu_obj_hop_put_locked(cfs_hash_t *hs, struct hlist_node *hnode)
         LBUG(); /* we should never called it */
 }
 
-cfs_hash_ops_t lu_site_hash_ops = {
+static cfs_hash_ops_t lu_site_hash_ops = {
         .hs_hash        = lu_obj_hop_hash,
         .hs_key         = lu_obj_hop_key,
         .hs_keycmp      = lu_obj_hop_keycmp,
@@ -1094,17 +1050,16 @@ int lu_site_init(struct lu_site *s, struct lu_device *top)
        struct lu_site_bkt_data *bkt;
        cfs_hash_bd_t bd;
        char name[16];
-       int bits;
-       int i;
+       unsigned long bits;
+       unsigned int i;
        ENTRY;
 
-       INIT_LIST_HEAD(&lu_sites);
-
        memset(s, 0, sizeof *s);
        mutex_init(&s->ls_purge_mutex);
        bits = lu_htable_order(top);
-       snprintf(name, 16, "lu_site_%s", top->ld_type->ldt_name);
-       for (bits = min(max(LU_SITE_BITS_MIN, bits), LU_SITE_BITS_MAX);
+       snprintf(name, sizeof(name), "lu_site_%s", top->ld_type->ldt_name);
+       for (bits = clamp_t(typeof(bits), bits,
+                           LU_SITE_BITS_MIN, LU_SITE_BITS_MAX);
             bits >= LU_SITE_BITS_MIN; bits--) {
                s->ls_obj_hash = cfs_hash_create(name, bits, bits,
                                                 bits - LU_SITE_BKT_BITS,
@@ -1120,7 +1075,7 @@ int lu_site_init(struct lu_site *s, struct lu_device *top)
        }
 
        if (s->ls_obj_hash == NULL) {
-               CERROR("failed to create lu_site hash with bits: %d\n", bits);
+               CERROR("failed to create lu_site hash with bits: %lu\n", bits);
                return -ENOMEM;
        }
 
@@ -1431,8 +1386,8 @@ static unsigned key_set_version = 0;
  */
 int lu_context_key_register(struct lu_context_key *key)
 {
-        int result;
-        int i;
+       int result;
+       unsigned int i;
 
         LASSERT(key->lct_init != NULL);
         LASSERT(key->lct_fini != NULL);
@@ -1642,7 +1597,7 @@ EXPORT_SYMBOL(lu_context_key_revive);
 
 static void keys_fini(struct lu_context *ctx)
 {
-       int     i;
+       unsigned int i;
 
        if (ctx->lc_value == NULL)
                return;
@@ -1656,7 +1611,7 @@ static void keys_fini(struct lu_context *ctx)
 
 static int keys_fill(struct lu_context *ctx)
 {
-        int i;
+       unsigned int i;
 
         LINVRNT(ctx->lc_value != NULL);
         for (i = 0; i < ARRAY_SIZE(lu_keys); ++i) {
@@ -1769,7 +1724,7 @@ EXPORT_SYMBOL(lu_context_enter);
  */
 void lu_context_exit(struct lu_context *ctx)
 {
-        int i;
+       unsigned int i;
 
         LINVRNT(ctx->lc_state == LCS_ENTERED);
         ctx->lc_state = LCS_LEFT;
@@ -1917,8 +1872,8 @@ typedef struct lu_site_stats{
 static void lu_site_stats_get(cfs_hash_t *hs,
                               lu_site_stats_t *stats, int populated)
 {
-        cfs_hash_bd_t bd;
-        int           i;
+       cfs_hash_bd_t bd;
+       unsigned int  i;
 
         cfs_hash_for_each_bucket(hs, &bd, i) {
                 struct lu_site_bkt_data *bkt = cfs_hash_bd_extra_get(hs, &bd);
@@ -1942,7 +1897,6 @@ static void lu_site_stats_get(cfs_hash_t *hs,
         }
 }
 
-#ifdef __KERNEL__
 
 static unsigned long lu_cache_shrink_count(struct shrinker *sk,
                                           struct shrink_control *sc)
@@ -2056,13 +2010,13 @@ static int lu_cache_shrink(SHRINKER_ARGS(sc, nr_to_scan, gfp_mask))
 /**
  * Environment to be used in debugger, contains all tags.
  */
-struct lu_env lu_debugging_env;
+static struct lu_env lu_debugging_env;
 
 /**
  * Debugging printer function using printk().
  */
 int lu_printk_printer(const struct lu_env *env,
-                      void *unused, const char *format, ...)
+                     void *unused, const char *format, ...)
 {
         va_list args;
 
@@ -2079,7 +2033,7 @@ int lu_debugging_setup(void)
 
 void lu_context_keys_dump(void)
 {
-        int i;
+       unsigned int i;
 
         for (i = 0; i < ARRAY_SIZE(lu_keys); ++i) {
                 struct lu_context_key *key;
@@ -2097,7 +2051,6 @@ void lu_context_keys_dump(void)
         }
 }
 EXPORT_SYMBOL(lu_context_keys_dump);
-#endif /* __KERNEL__ */
 
 /**
  * Initialization of global lu_* data.
@@ -2112,6 +2065,7 @@ int lu_global_init(void)
 
        INIT_LIST_HEAD(&lu_device_types);
        INIT_LIST_HEAD(&lu_context_remembered);
+       INIT_LIST_HEAD(&lu_sites);
 
         result = lu_ref_global_init();
         if (result != 0)
@@ -2170,7 +2124,7 @@ void lu_global_fini(void)
 
 static __u32 ls_stats_read(struct lprocfs_stats *stats, int idx)
 {
-#ifdef LPROCFS
+#ifdef CONFIG_PROC_FS
         struct lprocfs_counter ret;
 
         lprocfs_stats_collect(stats, idx, &ret);
@@ -2334,7 +2288,7 @@ void lu_buf_free(struct lu_buf *buf)
 }
 EXPORT_SYMBOL(lu_buf_free);
 
-void lu_buf_alloc(struct lu_buf *buf, int size)
+void lu_buf_alloc(struct lu_buf *buf, size_t size)
 {
        LASSERT(buf);
        LASSERT(buf->lb_buf == NULL);
@@ -2345,14 +2299,14 @@ void lu_buf_alloc(struct lu_buf *buf, int size)
 }
 EXPORT_SYMBOL(lu_buf_alloc);
 
-void lu_buf_realloc(struct lu_buf *buf, int size)
+void lu_buf_realloc(struct lu_buf *buf, size_t size)
 {
        lu_buf_free(buf);
        lu_buf_alloc(buf, size);
 }
 EXPORT_SYMBOL(lu_buf_realloc);
 
-struct lu_buf *lu_buf_check_and_alloc(struct lu_buf *buf, int len)
+struct lu_buf *lu_buf_check_and_alloc(struct lu_buf *buf, size_t len)
 {
        if (buf->lb_buf == NULL && buf->lb_len == 0)
                lu_buf_alloc(buf, len);
@@ -2370,7 +2324,7 @@ EXPORT_SYMBOL(lu_buf_check_and_alloc);
  * old buffer remains unchanged on error
  * \retval 0 or -ENOMEM
  */
-int lu_buf_check_and_grow(struct lu_buf *buf, int len)
+int lu_buf_check_and_grow(struct lu_buf *buf, size_t len)
 {
        char *ptr;
 
@@ -2392,4 +2346,3 @@ int lu_buf_check_and_grow(struct lu_buf *buf, int len)
        return 0;
 }
 EXPORT_SYMBOL(lu_buf_check_and_grow);
-