-/* -*- 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.
/*
* 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/
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);
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)
/* 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)
{
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)) {
* 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);
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);
c_list) {
if (!capa_is_expired(ocapa)) {
if (!next)
- update_capa_timer(ocapa, ocapa->c_expiry);
+ update_capa_timer(ocapa,
+ ocapa->c_expiry);
break;
}
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)
cfs_waitq_init(&ll_capa_thread.t_ctl_waitq);
- rc = cfs_kernel_thread(capa_thread_main, NULL, 0);
+ 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);
+ 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)
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;
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);
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);
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");
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");
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);
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)
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");
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 {
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)
/* 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)