Whamcloud - gitweb
LU-2800 autoconf: move LC_BLK_QUEUE_MAX_SEGMENTS test
[fs/lustre-release.git] / lustre / llite / llite_capa.c
index 7fcd704..7b6302d 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -28,6 +26,8 @@
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -92,13 +92,13 @@ static inline int capa_is_to_expire(struct obd_capa *ocapa)
 
 static inline int have_expired_capa(void)
 {
-        struct obd_capa *ocapa = NULL;
-        int expired = 0;
+       struct obd_capa *ocapa = NULL;
+       int expired = 0;
 
-        /* if ll_capa_list has client capa to expire or ll_idle_capas has
-         * expired capa, return 1.
-         */
-        cfs_spin_lock(&capa_lock);
+       /* if ll_capa_list has client capa to expire or ll_idle_capas has
+        * expired capa, return 1.
+        */
+       spin_lock(&capa_lock);
         if (!cfs_list_empty(ll_capa_list)) {
                 ocapa = cfs_list_entry(ll_capa_list->next, struct obd_capa,
                                        c_list);
@@ -112,16 +112,11 @@ static inline int have_expired_capa(void)
                 if (!expired)
                         update_capa_timer(ocapa, ocapa->c_expiry);
         }
-        cfs_spin_unlock(&capa_lock);
+       spin_unlock(&capa_lock);
 
-        if (expired)
-                DEBUG_CAPA(D_SEC, &ocapa->c_capa, "expired");
-        return expired;
-}
-
-static inline int ll_capa_check_stop(void)
-{
-        return (ll_capa_thread.t_flags & SVC_STOPPING) ? 1: 0;
+       if (expired)
+               DEBUG_CAPA(D_SEC, &ocapa->c_capa, "expired");
+       return expired;
 }
 
 static void sort_add_capa(struct obd_capa *ocapa, cfs_list_t *head)
@@ -168,32 +163,31 @@ static void ll_delete_capa(struct obd_capa *ocapa)
 /* three places where client capa is deleted:
  * 1. capa_thread_main(), main place to delete expired capa.
  * 2. ll_clear_inode_capas() in ll_clear_inode().
- * 3. ll_truncate_free_capa() delete truncate capa explicitly in ll_truncate().
+ * 3. ll_truncate_free_capa() delete truncate capa explicitly in ll_setattr_ost().
  */
 static int capa_thread_main(void *unused)
 {
-        struct obd_capa *ocapa, *tmp, *next;
-        struct inode *inode = NULL;
-        struct l_wait_info lwi = { 0 };
-        int rc;
-        ENTRY;
-
-        cfs_daemonize("ll_capa");
-
-        ll_capa_thread.t_flags = SVC_RUNNING;
-        cfs_waitq_signal(&ll_capa_thread.t_ctl_waitq);
-
-        while (1) {
-                l_wait_event(ll_capa_thread.t_ctl_waitq,
-                             (ll_capa_check_stop() || have_expired_capa()),
-                             &lwi);
-
-                if (ll_capa_check_stop())
+       struct obd_capa *ocapa, *tmp, *next;
+       struct inode *inode = NULL;
+       struct l_wait_info lwi = { 0 };
+       int rc;
+       ENTRY;
+
+       thread_set_flags(&ll_capa_thread, SVC_RUNNING);
+       wake_up(&ll_capa_thread.t_ctl_waitq);
+
+       while (1) {
+               l_wait_event(ll_capa_thread.t_ctl_waitq,
+                            !thread_is_running(&ll_capa_thread) ||
+                            have_expired_capa(),
+                            &lwi);
+
+                if (!thread_is_running(&ll_capa_thread))
                         break;
 
                 next = NULL;
 
-                cfs_spin_lock(&capa_lock);
+               spin_lock(&capa_lock);
                 cfs_list_for_each_entry_safe(ocapa, tmp, ll_capa_list, c_list) {
                         __u64 ibits;
 
@@ -245,10 +239,10 @@ static int capa_thread_main(void *unused)
 
                         capa_get(ocapa);
                         ll_capa_renewed++;
-                        cfs_spin_unlock(&capa_lock);
-                        rc = md_renew_capa(ll_i2mdexp(inode), ocapa,
-                                           ll_update_capa);
-                        cfs_spin_lock(&capa_lock);
+                       spin_unlock(&capa_lock);
+                       rc = md_renew_capa(ll_i2mdexp(inode), ocapa,
+                                          ll_update_capa);
+                       spin_lock(&capa_lock);
                         if (rc) {
                                 DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
                                            "renew failed: %d", rc);
@@ -282,43 +276,44 @@ static int capa_thread_main(void *unused)
                         ll_delete_capa(ocapa);
                 }
 
-                cfs_spin_unlock(&capa_lock);
-        }
+               spin_unlock(&capa_lock);
+       }
 
-        ll_capa_thread.t_flags = SVC_STOPPED;
-        cfs_waitq_signal(&ll_capa_thread.t_ctl_waitq);
-        RETURN(0);
+       thread_set_flags(&ll_capa_thread, SVC_STOPPED);
+       wake_up(&ll_capa_thread.t_ctl_waitq);
+       RETURN(0);
 }
 
 void ll_capa_timer_callback(unsigned long unused)
 {
-        cfs_waitq_signal(&ll_capa_thread.t_ctl_waitq);
+       wake_up(&ll_capa_thread.t_ctl_waitq);
 }
 
 int ll_capa_thread_start(void)
 {
-        int rc;
-        ENTRY;
+       struct task_struct *task;
+       ENTRY;
 
-        cfs_waitq_init(&ll_capa_thread.t_ctl_waitq);
+       init_waitqueue_head(&ll_capa_thread.t_ctl_waitq);
 
-        rc = cfs_create_thread(capa_thread_main, NULL, 0);
-        if (rc < 0) {
-                CERROR("cannot start expired capa thread: rc %d\n", rc);
-                RETURN(rc);
-        }
-        cfs_wait_event(ll_capa_thread.t_ctl_waitq,
-                       ll_capa_thread.t_flags & SVC_RUNNING);
+       task = kthread_run(capa_thread_main, NULL, "ll_capa");
+       if (IS_ERR(task)) {
+               CERROR("cannot start expired capa thread: rc %ld\n",
+                       PTR_ERR(task));
+               RETURN(PTR_ERR(task));
+       }
+       wait_event(ll_capa_thread.t_ctl_waitq,
+                      thread_is_running(&ll_capa_thread));
 
-        RETURN(0);
+       RETURN(0);
 }
 
 void ll_capa_thread_stop(void)
 {
-        ll_capa_thread.t_flags = SVC_STOPPING;
-        cfs_waitq_signal(&ll_capa_thread.t_ctl_waitq);
-        cfs_wait_event(ll_capa_thread.t_ctl_waitq,
-                       ll_capa_thread.t_flags & SVC_STOPPED);
+       thread_set_flags(&ll_capa_thread, SVC_STOPPING);
+       wake_up(&ll_capa_thread.t_ctl_waitq);
+       wait_event(ll_capa_thread.t_ctl_waitq,
+                      thread_is_stopped(&ll_capa_thread));
 }
 
 struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc)
@@ -335,7 +330,7 @@ struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc)
         LASSERT(opc == CAPA_OPC_OSS_WRITE || opc == CAPA_OPC_OSS_RW ||
                 opc == CAPA_OPC_OSS_TRUNC);
 
-        cfs_spin_lock(&capa_lock);
+       spin_lock(&capa_lock);
         cfs_list_for_each_entry(ocapa, &lli->lli_oss_capas, u.cli.lli_list) {
                 if (capa_is_expired(ocapa))
                         continue;
@@ -372,9 +367,9 @@ struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc)
                         cfs_atomic_set(&ll_capa_debug, 0);
                 }
         }
-        cfs_spin_unlock(&capa_lock);
+       spin_unlock(&capa_lock);
 
-        RETURN(ocapa);
+       RETURN(ocapa);
 }
 EXPORT_SYMBOL(ll_osscapa_get);
 
@@ -389,9 +384,9 @@ struct obd_capa *ll_mdscapa_get(struct inode *inode)
         if ((ll_i2sbi(inode)->ll_flags & LL_SBI_MDS_CAPA) == 0)
                 RETURN(NULL);
 
-        cfs_spin_lock(&capa_lock);
-        ocapa = capa_get(lli->lli_mds_capa);
-        cfs_spin_unlock(&capa_lock);
+       spin_lock(&capa_lock);
+       ocapa = capa_get(lli->lli_mds_capa);
+       spin_unlock(&capa_lock);
         if (!ocapa && cfs_atomic_read(&ll_capa_debug)) {
                 CERROR("no mds capability for "DFID"\n", PFID(&lli->lli_fid));
                 cfs_atomic_set(&ll_capa_debug, 0);
@@ -414,9 +409,9 @@ static struct obd_capa *do_add_mds_capa(struct inode *inode,
 
                 DEBUG_CAPA(D_SEC, capa, "add MDS");
         } else {
-                cfs_spin_lock(&old->c_lock);
-                old->c_capa = *capa;
-                cfs_spin_unlock(&old->c_lock);
+               spin_lock(&old->c_lock);
+               old->c_capa = *capa;
+               spin_unlock(&old->c_lock);
 
                 DEBUG_CAPA(D_SEC, capa, "update MDS");
 
@@ -485,9 +480,9 @@ static struct obd_capa *do_add_oss_capa(struct inode *inode,
 
                 DEBUG_CAPA(D_SEC, capa, "add OSS");
         } else {
-                cfs_spin_lock(&old->c_lock);
-                old->c_capa = *capa;
-                cfs_spin_unlock(&old->c_lock);
+               spin_lock(&old->c_lock);
+               old->c_capa = *capa;
+               spin_unlock(&old->c_lock);
 
                 DEBUG_CAPA(D_SEC, capa, "update OSS");
 
@@ -501,7 +496,7 @@ static struct obd_capa *do_add_oss_capa(struct inode *inode,
 
 struct obd_capa *ll_add_capa(struct inode *inode, struct obd_capa *ocapa)
 {
-        cfs_spin_lock(&capa_lock);
+       spin_lock(&capa_lock);
         ocapa = capa_for_mds(&ocapa->c_capa) ? do_add_mds_capa(inode, ocapa) :
                                                do_add_oss_capa(inode, ocapa);
 
@@ -514,10 +509,10 @@ struct obd_capa *ll_add_capa(struct inode *inode, struct obd_capa *ocapa)
                 update_capa_timer(ocapa, capa_renewal_time(ocapa));
         }
 
-        cfs_spin_unlock(&capa_lock);
+       spin_unlock(&capa_lock);
 
-        cfs_atomic_set(&ll_capa_debug, 1);
-        return ocapa;
+       cfs_atomic_set(&ll_capa_debug, 1);
+       return ocapa;
 }
 
 static inline void delay_capa_renew(struct obd_capa *oc, cfs_time_t delay)
@@ -537,7 +532,7 @@ int ll_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa)
         if (IS_ERR(capa)) {
                 /* set error code */
                 rc = PTR_ERR(capa);
-                cfs_spin_lock(&capa_lock);
+               spin_lock(&capa_lock);
                 if (rc == -ENOENT) {
                         DEBUG_CAPA(D_SEC, &ocapa->c_capa,
                                    "renewal canceled because object removed");
@@ -562,34 +557,34 @@ int ll_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa)
 
                 cfs_list_del_init(&ocapa->c_list);
                 sort_add_capa(ocapa, &ll_idle_capas);
-                cfs_spin_unlock(&capa_lock);
-
-                capa_put(ocapa);
-                iput(inode);
-                RETURN(rc);
-        }
-
-        cfs_spin_lock(&ocapa->c_lock);
-        LASSERT(!memcmp(&ocapa->c_capa, capa,
-                        offsetof(struct lustre_capa, lc_opc)));
-        ocapa->c_capa = *capa;
-        set_capa_expiry(ocapa);
-        cfs_spin_unlock(&ocapa->c_lock);
-
-        cfs_spin_lock(&capa_lock);
-        if (capa_for_oss(capa))
-                inode_add_oss_capa(inode, ocapa);
-        DEBUG_CAPA(D_SEC, capa, "renew");
-        EXIT;
+               spin_unlock(&capa_lock);
+
+               capa_put(ocapa);
+               iput(inode);
+               RETURN(rc);
+       }
+
+       spin_lock(&ocapa->c_lock);
+       LASSERT(!memcmp(&ocapa->c_capa, capa,
+                       offsetof(struct lustre_capa, lc_opc)));
+       ocapa->c_capa = *capa;
+       set_capa_expiry(ocapa);
+       spin_unlock(&ocapa->c_lock);
+
+       spin_lock(&capa_lock);
+       if (capa_for_oss(capa))
+               inode_add_oss_capa(inode, ocapa);
+       DEBUG_CAPA(D_SEC, capa, "renew");
+       EXIT;
 retry:
-        cfs_list_del_init(&ocapa->c_list);
-        sort_add_capa(ocapa, ll_capa_list);
-        update_capa_timer(ocapa, capa_renewal_time(ocapa));
-        cfs_spin_unlock(&capa_lock);
-
-        capa_put(ocapa);
-        iput(inode);
-        return rc;
+       cfs_list_del_init(&ocapa->c_list);
+       sort_add_capa(ocapa, ll_capa_list);
+       update_capa_timer(ocapa, capa_renewal_time(ocapa));
+       spin_unlock(&capa_lock);
+
+       capa_put(ocapa);
+       iput(inode);
+       return rc;
 }
 
 void ll_capa_open(struct inode *inode)
@@ -632,26 +627,26 @@ void ll_truncate_free_capa(struct obd_capa *ocapa)
         /* release ref when find */
         capa_put(ocapa);
         if (likely(ocapa->c_capa.lc_opc == CAPA_OPC_OSS_TRUNC)) {
-                cfs_spin_lock(&capa_lock);
-                ll_delete_capa(ocapa);
-                cfs_spin_unlock(&capa_lock);
-        }
+               spin_lock(&capa_lock);
+               ll_delete_capa(ocapa);
+               spin_unlock(&capa_lock);
+       }
 }
 
 void ll_clear_inode_capas(struct inode *inode)
 {
-        struct ll_inode_info *lli = ll_i2info(inode);
-        struct obd_capa *ocapa, *tmp;
-
-        cfs_spin_lock(&capa_lock);
-        ocapa = lli->lli_mds_capa;
-        if (ocapa)
-                ll_delete_capa(ocapa);
-
-        cfs_list_for_each_entry_safe(ocapa, tmp, &lli->lli_oss_capas,
-                                     u.cli.lli_list)
-                ll_delete_capa(ocapa);
-        cfs_spin_unlock(&capa_lock);
+       struct ll_inode_info *lli = ll_i2info(inode);
+       struct obd_capa *ocapa, *tmp;
+
+       spin_lock(&capa_lock);
+       ocapa = lli->lli_mds_capa;
+       if (ocapa)
+               ll_delete_capa(ocapa);
+
+       cfs_list_for_each_entry_safe(ocapa, tmp, &lli->lli_oss_capas,
+                                    u.cli.lli_list)
+               ll_delete_capa(ocapa);
+       spin_unlock(&capa_lock);
 }
 
 void ll_print_capa_stat(struct ll_sb_info *sbi)