X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fllite%2Fllite_capa.c;h=1d489e60b35045ee73a3f5f0176c91f3afb0ed2b;hb=4e57f6dd3a156e35ccb587fc5c003805dd73ecb7;hp=1fcfacf2d21ce33e499a1c1767b50eef93858dd2;hpb=adb6cea0b70ac465b2a47635d9dc45d64ab1605b;p=fs%2Flustre-release.git diff --git a/lustre/llite/llite_capa.c b/lustre/llite/llite_capa.c index 1fcfacf..1d489e6 100644 --- a/lustre/llite/llite_capa.c +++ b/lustre/llite/llite_capa.c @@ -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) 2011, 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,7 +163,7 @@ 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) { @@ -180,21 +175,24 @@ static int capa_thread_main(void *unused) cfs_daemonize("ll_capa"); - ll_capa_thread.t_flags = SVC_RUNNING; + thread_set_flags(&ll_capa_thread, 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()), + !thread_is_running(&ll_capa_thread) || + have_expired_capa(), &lwi); - if (ll_capa_check_stop()) + 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; + LASSERT(ocapa->c_capa.lc_opc != CAPA_OPC_OSS_TRUNC); if (!capa_is_to_expire(ocapa)) { @@ -208,12 +206,14 @@ static int capa_thread_main(void *unused) * dir, or its inode is opened, or client holds LOOKUP * lock. */ + /* ibits may be changed by ll_have_md_lock() so we have + * to set it each time */ + ibits = MDS_INODELOCK_LOOKUP; if (capa_for_mds(&ocapa->c_capa) && !S_ISDIR(ocapa->u.cli.inode->i_mode) && obd_capa_open_count(ocapa) == 0 && !ll_have_md_lock(ocapa->u.cli.inode, - MDS_INODELOCK_LOOKUP, - LCK_MINMODE)) { + &ibits, LCK_MINMODE)) { DEBUG_CAPA(D_SEC, &ocapa->c_capa, "skip renewal for"); sort_add_capa(ocapa, &ll_idle_capas); @@ -241,10 +241,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); @@ -259,7 +259,8 @@ static int capa_thread_main(void *unused) c_list) { if (!capa_is_expired(ocapa)) { if (!next) - update_capa_timer(ocapa, ocapa->c_expiry); + update_capa_timer(ocapa, + ocapa->c_expiry); break; } @@ -277,12 +278,12 @@ 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); + cfs_waitq_signal(&ll_capa_thread.t_ctl_waitq); + RETURN(0); } void ll_capa_timer_callback(unsigned long unused) @@ -303,17 +304,17 @@ int ll_capa_thread_start(void) RETURN(rc); } cfs_wait_event(ll_capa_thread.t_ctl_waitq, - ll_capa_thread.t_flags & SVC_RUNNING); + thread_is_running(&ll_capa_thread)); RETURN(0); } void ll_capa_thread_stop(void) { - ll_capa_thread.t_flags = SVC_STOPPING; + thread_set_flags(&ll_capa_thread, 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_is_stopped(&ll_capa_thread)); } struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc) @@ -330,7 +331,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; @@ -367,9 +368,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); @@ -384,9 +385,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); @@ -409,9 +410,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"); @@ -480,9 +481,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"); @@ -496,7 +497,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); @@ -509,10 +510,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) @@ -532,7 +533,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"); @@ -545,7 +546,8 @@ int ll_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa) if (rc == -EIO && !capa_is_expired(ocapa)) { delay_capa_renew(ocapa, 120); DEBUG_CAPA(D_ERROR, &ocapa->c_capa, - "renewal failed: -EIO, retry in 2 mins"); + "renewal failed: -EIO, " + "retry in 2 mins"); ll_capa_renewal_retries++; GOTO(retry, rc); } else { @@ -556,34 +558,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) @@ -626,26 +628,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)