Whamcloud - gitweb
LU-5577 obdclass: change lu_site->ls_purge_start to unsigned
[fs/lustre-release.git] / lustre / obdclass / lu_object.c
index d880ba4..cb19029 100644 (file)
 #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>
@@ -348,11 +343,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);
@@ -610,10 +605,13 @@ 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);
+       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);
+       }
+
        return ERR_PTR(-EAGAIN);
 }
 
@@ -799,6 +797,12 @@ struct lu_object *lu_object_find_at(const struct lu_env *env,
        wait_queue_t           wait;
 
        while (1) {
+               if (conf != NULL && conf->loc_flags & LOC_F_NOWAIT) {
+                       obj = lu_object_find_try(env, dev, f, conf, NULL);
+
+                       return obj;
+               }
+
                obj = lu_object_find_try(env, dev, f, conf, &wait);
                if (obj != ERR_PTR(-EAGAIN))
                        return obj;
@@ -950,10 +954,10 @@ EXPORT_SYMBOL(lu_site_print);
 /**
  * Return desired hash table order.
  */
-static int lu_htable_order(struct lu_device *top)
+static unsigned int lu_htable_order(struct lu_device *top)
 {
-        unsigned long cache_size;
-        int bits;
+       unsigned long cache_size;
+       unsigned int  bits;
 
        /*
         * For ZFS based OSDs the cache should be disabled by default.  This
@@ -1094,15 +1098,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 int bits;
+       unsigned int i;
        ENTRY;
 
        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);
+       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,
@@ -1429,8 +1434,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);
@@ -1640,7 +1645,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;
@@ -1654,7 +1659,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) {
@@ -1767,7 +1772,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;
@@ -1915,8 +1920,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);
@@ -1940,7 +1945,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)
@@ -2077,7 +2081,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;
@@ -2095,7 +2099,6 @@ void lu_context_keys_dump(void)
         }
 }
 EXPORT_SYMBOL(lu_context_keys_dump);
-#endif /* __KERNEL__ */
 
 /**
  * Initialization of global lu_* data.
@@ -2333,7 +2336,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);
@@ -2344,14 +2347,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);
@@ -2369,7 +2372,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;