X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fllite%2Fllite_capa.c;h=57ec8180c0645544ec562916d1396360d50a1e6d;hb=da94c5388a4e4344e86b837ff35c2c693569fc77;hp=818008abd65e96dcfc66ea05bb1add5e04b2ec57;hpb=fbf5870b9848929d352460f1f005b79c0b5ccc5a;p=fs%2Flustre-release.git diff --git a/lustre/llite/llite_capa.c b/lustre/llite/llite_capa.c index 818008a..57ec818 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. @@ -26,8 +24,10 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2012, Whamcloud, Inc. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -56,14 +56,14 @@ */ /* capas for oss writeback and those failed to renew */ -static LIST_HEAD(ll_idle_capas); +static CFS_LIST_HEAD(ll_idle_capas); static struct ptlrpc_thread ll_capa_thread; -static struct list_head *ll_capa_list = &capa_list[CAPA_SITE_CLIENT]; +static cfs_list_t *ll_capa_list = &capa_list[CAPA_SITE_CLIENT]; /* llite capa renewal timer */ struct timer_list ll_capa_timer; /* for debug: indicate whether capa on llite is enabled or not */ -static atomic_t ll_capa_debug = ATOMIC_INIT(0); +static cfs_atomic_t ll_capa_debug = CFS_ATOMIC_INIT(0); static unsigned long long ll_capa_renewed = 0; static unsigned long long ll_capa_renewal_noent = 0; static unsigned long long ll_capa_renewal_failed = 0; @@ -71,7 +71,7 @@ static unsigned long long ll_capa_renewal_retries = 0; static inline void update_capa_timer(struct obd_capa *ocapa, cfs_time_t expiry) { - if (time_before(expiry, ll_capa_timer.expires) || + if (cfs_time_before(expiry, ll_capa_timer.expires) || !timer_pending(&ll_capa_timer)) { mod_timer(&ll_capa_timer, expiry); DEBUG_CAPA(D_SEC, &ocapa->c_capa, @@ -98,37 +98,34 @@ static inline int have_expired_capa(void) /* if ll_capa_list has client capa to expire or ll_idle_capas has * expired capa, return 1. */ - spin_lock(&capa_lock); - if (!list_empty(ll_capa_list)) { - ocapa = list_entry(ll_capa_list->next, struct obd_capa, c_list); + cfs_spin_lock(&capa_lock); + if (!cfs_list_empty(ll_capa_list)) { + ocapa = cfs_list_entry(ll_capa_list->next, struct obd_capa, + c_list); expired = capa_is_to_expire(ocapa); if (!expired) update_capa_timer(ocapa, capa_renewal_time(ocapa)); - } else if (!list_empty(&ll_idle_capas)) { - ocapa = list_entry(ll_idle_capas.next, struct obd_capa, c_list); + } else if (!cfs_list_empty(&ll_idle_capas)) { + ocapa = cfs_list_entry(ll_idle_capas.next, struct obd_capa, + c_list); expired = capa_is_expired(ocapa); if (!expired) update_capa_timer(ocapa, ocapa->c_expiry); } - spin_unlock(&capa_lock); + cfs_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; -} - -static void sort_add_capa(struct obd_capa *ocapa, struct list_head *head) +static void sort_add_capa(struct obd_capa *ocapa, cfs_list_t *head) { struct obd_capa *tmp; - struct list_head *before = NULL; + cfs_list_t *before = NULL; /* TODO: client capa is sorted by expiry, this could be optimized */ - list_for_each_entry_reverse(tmp, head, c_list) { + cfs_list_for_each_entry_reverse(tmp, head, c_list) { if (cfs_time_aftereq(ocapa->c_expiry, tmp->c_expiry)) { before = &tmp->c_list; break; @@ -136,13 +133,13 @@ static void sort_add_capa(struct obd_capa *ocapa, struct list_head *head) } LASSERT(&ocapa->c_list != before); - list_add(&ocapa->c_list, before ?: head); + cfs_list_add(&ocapa->c_list, before ?: head); } static inline int obd_capa_open_count(struct obd_capa *oc) { struct ll_inode_info *lli = ll_i2info(oc->u.cli.inode); - return atomic_read(&lli->lli_open_count); + return cfs_atomic_read(&lli->lli_open_count); } static void ll_delete_capa(struct obd_capa *ocapa) @@ -153,13 +150,14 @@ static void ll_delete_capa(struct obd_capa *ocapa) LASSERT(lli->lli_mds_capa == ocapa); lli->lli_mds_capa = NULL; } else if (capa_for_oss(&ocapa->c_capa)) { - list_del_init(&ocapa->u.cli.lli_list); + cfs_list_del_init(&ocapa->u.cli.lli_list); } DEBUG_CAPA(D_SEC, &ocapa->c_capa, "free client"); - list_del(&ocapa->c_list); + cfs_list_del_init(&ocapa->c_list); capa_count[CAPA_SITE_CLIENT]--; - free_capa(ocapa); + /* release the ref when alloc */ + capa_put(ocapa); } /* three places where client capa is deleted: @@ -177,21 +175,24 @@ static int capa_thread_main(void *unused) cfs_daemonize("ll_capa"); - ll_capa_thread.t_flags = SVC_RUNNING; - wake_up(&ll_capa_thread.t_ctl_waitq); + 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; - spin_lock(&capa_lock); - list_for_each_entry_safe(ocapa, tmp, ll_capa_list, c_list) { + cfs_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)) { @@ -199,17 +200,20 @@ static int capa_thread_main(void *unused) break; } - list_del_init(&ocapa->c_list); + cfs_list_del_init(&ocapa->c_list); /* for MDS capability, only renew those which belong to * 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)) { + &ibits, LCK_MINMODE)) { DEBUG_CAPA(D_SEC, &ocapa->c_capa, "skip renewal for"); sort_add_capa(ocapa, &ll_idle_capas); @@ -237,11 +241,10 @@ static int capa_thread_main(void *unused) capa_get(ocapa); ll_capa_renewed++; - spin_unlock(&capa_lock); - + cfs_spin_unlock(&capa_lock); rc = md_renew_capa(ll_i2mdexp(inode), ocapa, ll_update_capa); - spin_lock(&capa_lock); + cfs_spin_lock(&capa_lock); if (rc) { DEBUG_CAPA(D_ERROR, &ocapa->c_capa, "renew failed: %d", rc); @@ -252,19 +255,21 @@ static int capa_thread_main(void *unused) if (next) update_capa_timer(next, capa_renewal_time(next)); - list_for_each_entry_safe(ocapa, tmp, &ll_idle_capas, c_list) { + cfs_list_for_each_entry_safe(ocapa, tmp, &ll_idle_capas, + c_list) { if (!capa_is_expired(ocapa)) { if (!next) - update_capa_timer(ocapa, ocapa->c_expiry); + update_capa_timer(ocapa, + ocapa->c_expiry); break; } - if (atomic_read(&ocapa->c_refc)) { + if (cfs_atomic_read(&ocapa->c_refc) > 1) { DEBUG_CAPA(D_SEC, &ocapa->c_capa, "expired(c_refc %d), don't release", - atomic_read(&ocapa->c_refc)); + cfs_atomic_read(&ocapa->c_refc)); /* don't try to renew any more */ - list_del_init(&ocapa->c_list); + cfs_list_del_init(&ocapa->c_list); continue; } @@ -273,17 +278,17 @@ static int capa_thread_main(void *unused) ll_delete_capa(ocapa); } - spin_unlock(&capa_lock); + cfs_spin_unlock(&capa_lock); } - ll_capa_thread.t_flags = SVC_STOPPED; - wake_up(&ll_capa_thread.t_ctl_waitq); + 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) { - wake_up(&ll_capa_thread.t_ctl_waitq); + cfs_waitq_signal(&ll_capa_thread.t_ctl_waitq); } int ll_capa_thread_start(void) @@ -291,46 +296,25 @@ int ll_capa_thread_start(void) int rc; ENTRY; - init_waitqueue_head(&ll_capa_thread.t_ctl_waitq); + cfs_waitq_init(&ll_capa_thread.t_ctl_waitq); - rc = 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); } - wait_event(ll_capa_thread.t_ctl_waitq, - ll_capa_thread.t_flags & SVC_RUNNING); + cfs_wait_event(ll_capa_thread.t_ctl_waitq, + thread_is_running(&ll_capa_thread)); RETURN(0); } void ll_capa_thread_stop(void) { - ll_capa_thread.t_flags = SVC_STOPPING; - wake_up(&ll_capa_thread.t_ctl_waitq); - wait_event(ll_capa_thread.t_ctl_waitq, - ll_capa_thread.t_flags & SVC_STOPPED); -} - -static struct obd_capa *do_lookup_oss_capa(struct inode *inode, int opc) -{ - struct ll_inode_info *lli = ll_i2info(inode); - struct obd_capa *ocapa; - - /* inside capa_lock */ - list_for_each_entry(ocapa, &lli->lli_oss_capas, u.cli.lli_list) { - if ((capa_opc(&ocapa->c_capa) & opc) != opc) - continue; - - LASSERT(lu_fid_eq(capa_fid(&ocapa->c_capa), - ll_inode2fid(inode))); - LASSERT(ocapa->c_site == CAPA_SITE_CLIENT); - - DEBUG_CAPA(D_SEC, &ocapa->c_capa, "found client"); - return ocapa; - } - - return NULL; + 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, + thread_is_stopped(&ll_capa_thread)); } struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc) @@ -347,20 +331,23 @@ 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); - spin_lock(&capa_lock); - list_for_each_entry(ocapa, &lli->lli_oss_capas, u.cli.lli_list) { + cfs_spin_lock(&capa_lock); + cfs_list_for_each_entry(ocapa, &lli->lli_oss_capas, u.cli.lli_list) { if (capa_is_expired(ocapa)) continue; if ((opc & CAPA_OPC_OSS_WRITE) && capa_opc_supported(&ocapa->c_capa, CAPA_OPC_OSS_WRITE)) { - found = 1; break; + found = 1; + break; } else if ((opc & CAPA_OPC_OSS_READ) && capa_opc_supported(&ocapa->c_capa, CAPA_OPC_OSS_READ)) { - found = 1; break; + found = 1; + break; } else if ((opc & CAPA_OPC_OSS_TRUNC) && capa_opc_supported(&ocapa->c_capa, opc)) { - found = 1; break; + found = 1; + break; } } @@ -375,13 +362,13 @@ struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc) } else { ocapa = NULL; - if (atomic_read(&ll_capa_debug)) { + if (cfs_atomic_read(&ll_capa_debug)) { CERROR("no capability for "DFID" opc "LPX64"\n", PFID(&lli->lli_fid), opc); - atomic_set(&ll_capa_debug, 0); + cfs_atomic_set(&ll_capa_debug, 0); } } - spin_unlock(&capa_lock); + cfs_spin_unlock(&capa_lock); RETURN(ocapa); } @@ -398,12 +385,12 @@ struct obd_capa *ll_mdscapa_get(struct inode *inode) if ((ll_i2sbi(inode)->ll_flags & LL_SBI_MDS_CAPA) == 0) RETURN(NULL); - spin_lock(&capa_lock); + cfs_spin_lock(&capa_lock); ocapa = capa_get(lli->lli_mds_capa); - spin_unlock(&capa_lock); - if (!ocapa && atomic_read(&ll_capa_debug)) { + cfs_spin_unlock(&capa_lock); + if (!ocapa && cfs_atomic_read(&ll_capa_debug)) { CERROR("no mds capability for "DFID"\n", PFID(&lli->lli_fid)); - atomic_set(&ll_capa_debug, 0); + cfs_atomic_set(&ll_capa_debug, 0); } RETURN(ocapa); @@ -423,35 +410,56 @@ static struct obd_capa *do_add_mds_capa(struct inode *inode, DEBUG_CAPA(D_SEC, capa, "add MDS"); } else { - spin_lock(&old->c_lock); + cfs_spin_lock(&old->c_lock); old->c_capa = *capa; - spin_unlock(&old->c_lock); + cfs_spin_unlock(&old->c_lock); DEBUG_CAPA(D_SEC, capa, "update MDS"); - free_capa(ocapa); + capa_put(ocapa); ocapa = old; } return ocapa; } +static struct obd_capa *do_lookup_oss_capa(struct inode *inode, int opc) +{ + struct ll_inode_info *lli = ll_i2info(inode); + struct obd_capa *ocapa; + + /* inside capa_lock */ + cfs_list_for_each_entry(ocapa, &lli->lli_oss_capas, u.cli.lli_list) { + if ((capa_opc(&ocapa->c_capa) & opc) != opc) + continue; + + LASSERT(lu_fid_eq(capa_fid(&ocapa->c_capa), + ll_inode2fid(inode))); + LASSERT(ocapa->c_site == CAPA_SITE_CLIENT); + + DEBUG_CAPA(D_SEC, &ocapa->c_capa, "found client"); + return ocapa; + } + + return NULL; +} + static inline void inode_add_oss_capa(struct inode *inode, struct obd_capa *ocapa) { struct ll_inode_info *lli = ll_i2info(inode); struct obd_capa *tmp; - struct list_head *next = NULL; + cfs_list_t *next = NULL; /* capa is sorted in lli_oss_capas so lookup can always find the * latest one */ - list_for_each_entry(tmp, &lli->lli_oss_capas, u.cli.lli_list) { + cfs_list_for_each_entry(tmp, &lli->lli_oss_capas, u.cli.lli_list) { if (cfs_time_after(ocapa->c_expiry, tmp->c_expiry)) { next = &tmp->u.cli.lli_list; break; } } LASSERT(&ocapa->u.cli.lli_list != next); - list_move_tail(&ocapa->u.cli.lli_list, next ?: &lli->lli_oss_capas); + cfs_list_move_tail(&ocapa->u.cli.lli_list, next ?: &lli->lli_oss_capas); } static struct obd_capa *do_add_oss_capa(struct inode *inode, @@ -468,18 +476,18 @@ static struct obd_capa *do_add_oss_capa(struct inode *inode, old = do_lookup_oss_capa(inode, capa_opc(capa) & CAPA_OPC_OSS_ONLY); if (!old) { ocapa->u.cli.inode = inode; - INIT_LIST_HEAD(&ocapa->u.cli.lli_list); + CFS_INIT_LIST_HEAD(&ocapa->u.cli.lli_list); capa_count[CAPA_SITE_CLIENT]++; DEBUG_CAPA(D_SEC, capa, "add OSS"); } else { - spin_lock(&old->c_lock); + cfs_spin_lock(&old->c_lock); old->c_capa = *capa; - spin_unlock(&old->c_lock); + cfs_spin_unlock(&old->c_lock); DEBUG_CAPA(D_SEC, capa, "update OSS"); - free_capa(ocapa); + capa_put(ocapa); ocapa = old; } @@ -489,22 +497,22 @@ static struct obd_capa *do_add_oss_capa(struct inode *inode, struct obd_capa *ll_add_capa(struct inode *inode, struct obd_capa *ocapa) { - spin_lock(&capa_lock); + cfs_spin_lock(&capa_lock); ocapa = capa_for_mds(&ocapa->c_capa) ? do_add_mds_capa(inode, ocapa) : do_add_oss_capa(inode, ocapa); /* truncate capa won't renew */ if (ocapa->c_capa.lc_opc != CAPA_OPC_OSS_TRUNC) { set_capa_expiry(ocapa); - list_del(&ocapa->c_list); + 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); + cfs_spin_unlock(&capa_lock); - atomic_set(&ll_capa_debug, 1); + cfs_atomic_set(&ll_capa_debug, 1); return ocapa; } @@ -525,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); - spin_lock(&capa_lock); + cfs_spin_lock(&capa_lock); if (rc == -ENOENT) { DEBUG_CAPA(D_SEC, &ocapa->c_capa, "renewal canceled because object removed"); @@ -538,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 { @@ -547,32 +556,32 @@ int ll_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa) } } - list_del(&ocapa->c_list); + cfs_list_del_init(&ocapa->c_list); sort_add_capa(ocapa, &ll_idle_capas); - spin_unlock(&capa_lock); + cfs_spin_unlock(&capa_lock); capa_put(ocapa); iput(inode); - return rc; + RETURN(rc); } - spin_lock(&ocapa->c_lock); + cfs_spin_lock(&ocapa->c_lock); LASSERT(!memcmp(&ocapa->c_capa, capa, - offsetof(struct lustre_capa, lc_flags))); + offsetof(struct lustre_capa, lc_opc))); ocapa->c_capa = *capa; set_capa_expiry(ocapa); - spin_unlock(&ocapa->c_lock); + cfs_spin_unlock(&ocapa->c_lock); - spin_lock(&capa_lock); + cfs_spin_lock(&capa_lock); if (capa_for_oss(capa)) inode_add_oss_capa(inode, ocapa); DEBUG_CAPA(D_SEC, capa, "renew"); EXIT; retry: - list_del_init(&ocapa->c_list); + 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); + cfs_spin_unlock(&capa_lock); capa_put(ocapa); iput(inode); @@ -590,7 +599,7 @@ void ll_capa_open(struct inode *inode) if (!S_ISREG(inode->i_mode)) return; - atomic_inc(&lli->lli_open_count); + cfs_atomic_inc(&lli->lli_open_count); } void ll_capa_close(struct inode *inode) @@ -604,7 +613,7 @@ void ll_capa_close(struct inode *inode) if (!S_ISREG(inode->i_mode)) return; - atomic_dec(&lli->lli_open_count); + cfs_atomic_dec(&lli->lli_open_count); } /* delete CAPA_OPC_OSS_TRUNC only */ @@ -616,10 +625,13 @@ void ll_truncate_free_capa(struct obd_capa *ocapa) LASSERT(ocapa->c_capa.lc_opc & CAPA_OPC_OSS_TRUNC); DEBUG_CAPA(D_SEC, &ocapa->c_capa, "free truncate"); + /* release ref when find */ capa_put(ocapa); - spin_lock(&capa_lock); - ll_delete_capa(ocapa); - spin_unlock(&capa_lock); + 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); + } } void ll_clear_inode_capas(struct inode *inode) @@ -627,15 +639,15 @@ void ll_clear_inode_capas(struct inode *inode) struct ll_inode_info *lli = ll_i2info(inode); struct obd_capa *ocapa, *tmp; - spin_lock(&capa_lock); + cfs_spin_lock(&capa_lock); ocapa = lli->lli_mds_capa; if (ocapa) ll_delete_capa(ocapa); - list_for_each_entry_safe(ocapa, tmp, &lli->lli_oss_capas, - u.cli.lli_list) + cfs_list_for_each_entry_safe(ocapa, tmp, &lli->lli_oss_capas, + u.cli.lli_list) ll_delete_capa(ocapa); - spin_unlock(&capa_lock); + cfs_spin_unlock(&capa_lock); } void ll_print_capa_stat(struct ll_sb_info *sbi)