X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;ds=sidebyside;f=lustre%2Fptlrpc%2Fsec_gc.c;h=a7f3b7946766cce77dd6b8517cd45e26e024d9b6;hb=6299d78713ef2b6f69f6dd046256aa91a85147a8;hp=344711c9ed5bd16daa4f956991c6a2106d48c210;hpb=6e3ec5812ebd1b5ecf7cae584f429b013ffe7431;p=fs%2Flustre-release.git diff --git a/lustre/ptlrpc/sec_gc.c b/lustre/ptlrpc/sec_gc.c index 344711c..a7f3b79 100644 --- a/lustre/ptlrpc/sec_gc.c +++ b/lustre/ptlrpc/sec_gc.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) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2012, 2014, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -38,114 +38,107 @@ * Author: Eric Mei */ -#ifndef EXPORT_SYMTAB -# define EXPORT_SYMTAB -#endif #define DEBUG_SUBSYSTEM S_SEC -#ifndef __KERNEL__ -#include -#else +#include #include -#endif #include #include #include #include +#include "ptlrpc_internal.h" + #define SEC_GC_INTERVAL (30 * 60) -#ifdef __KERNEL__ -static cfs_mutex_t sec_gc_mutex; -static CFS_LIST_HEAD(sec_gc_list); -static cfs_spinlock_t sec_gc_list_lock; +static struct mutex sec_gc_mutex; +static spinlock_t sec_gc_list_lock; +static struct list_head sec_gc_list; -static CFS_LIST_HEAD(sec_gc_ctx_list); -static cfs_spinlock_t sec_gc_ctx_list_lock; +static spinlock_t sec_gc_ctx_list_lock; +static struct list_head sec_gc_ctx_list; static struct ptlrpc_thread sec_gc_thread; -static cfs_atomic_t sec_gc_wait_del = CFS_ATOMIC_INIT(0); +static atomic_t sec_gc_wait_del = ATOMIC_INIT(0); void sptlrpc_gc_add_sec(struct ptlrpc_sec *sec) { LASSERT(sec->ps_policy->sp_cops->gc_ctx); LASSERT(sec->ps_gc_interval > 0); - LASSERT(cfs_list_empty(&sec->ps_gc_list)); + LASSERT(list_empty(&sec->ps_gc_list)); sec->ps_gc_next = cfs_time_current_sec() + sec->ps_gc_interval; - cfs_spin_lock(&sec_gc_list_lock); - cfs_list_add_tail(&sec_gc_list, &sec->ps_gc_list); - cfs_spin_unlock(&sec_gc_list_lock); + spin_lock(&sec_gc_list_lock); + list_add_tail(&sec_gc_list, &sec->ps_gc_list); + spin_unlock(&sec_gc_list_lock); - CDEBUG(D_SEC, "added sec %p(%s)\n", sec, sec->ps_policy->sp_name); + CDEBUG(D_SEC, "added sec %p(%s)\n", sec, sec->ps_policy->sp_name); } -EXPORT_SYMBOL(sptlrpc_gc_add_sec); void sptlrpc_gc_del_sec(struct ptlrpc_sec *sec) { - if (cfs_list_empty(&sec->ps_gc_list)) - return; + if (list_empty(&sec->ps_gc_list)) + return; - cfs_might_sleep(); + might_sleep(); - /* signal before list_del to make iteration in gc thread safe */ - cfs_atomic_inc(&sec_gc_wait_del); + /* signal before list_del to make iteration in gc thread safe */ + atomic_inc(&sec_gc_wait_del); - cfs_spin_lock(&sec_gc_list_lock); - cfs_list_del_init(&sec->ps_gc_list); - cfs_spin_unlock(&sec_gc_list_lock); + spin_lock(&sec_gc_list_lock); + list_del_init(&sec->ps_gc_list); + spin_unlock(&sec_gc_list_lock); - /* barrier */ - cfs_mutex_lock(&sec_gc_mutex); - cfs_mutex_unlock(&sec_gc_mutex); + /* barrier */ + mutex_lock(&sec_gc_mutex); + mutex_unlock(&sec_gc_mutex); - cfs_atomic_dec(&sec_gc_wait_del); + atomic_dec(&sec_gc_wait_del); - CDEBUG(D_SEC, "del sec %p(%s)\n", sec, sec->ps_policy->sp_name); + CDEBUG(D_SEC, "del sec %p(%s)\n", sec, sec->ps_policy->sp_name); } -EXPORT_SYMBOL(sptlrpc_gc_del_sec); void sptlrpc_gc_add_ctx(struct ptlrpc_cli_ctx *ctx) { - LASSERT(cfs_list_empty(&ctx->cc_gc_chain)); + LASSERT(list_empty(&ctx->cc_gc_chain)); - CDEBUG(D_SEC, "hand over ctx %p(%u->%s)\n", - ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec)); - cfs_spin_lock(&sec_gc_ctx_list_lock); - cfs_list_add(&ctx->cc_gc_chain, &sec_gc_ctx_list); - cfs_spin_unlock(&sec_gc_ctx_list_lock); + CDEBUG(D_SEC, "hand over ctx %p(%u->%s)\n", + ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec)); + spin_lock(&sec_gc_ctx_list_lock); + list_add(&ctx->cc_gc_chain, &sec_gc_ctx_list); + spin_unlock(&sec_gc_ctx_list_lock); - sec_gc_thread.t_flags |= SVC_SIGNAL; - cfs_waitq_signal(&sec_gc_thread.t_ctl_waitq); + thread_add_flags(&sec_gc_thread, SVC_SIGNAL); + wake_up(&sec_gc_thread.t_ctl_waitq); } EXPORT_SYMBOL(sptlrpc_gc_add_ctx); static void sec_process_ctx_list(void) { - struct ptlrpc_cli_ctx *ctx; + struct ptlrpc_cli_ctx *ctx; - cfs_spin_lock(&sec_gc_ctx_list_lock); + spin_lock(&sec_gc_ctx_list_lock); - while (!cfs_list_empty(&sec_gc_ctx_list)) { - ctx = cfs_list_entry(sec_gc_ctx_list.next, - struct ptlrpc_cli_ctx, cc_gc_chain); - cfs_list_del_init(&ctx->cc_gc_chain); - cfs_spin_unlock(&sec_gc_ctx_list_lock); + while (!list_empty(&sec_gc_ctx_list)) { + ctx = list_entry(sec_gc_ctx_list.next, + struct ptlrpc_cli_ctx, cc_gc_chain); + list_del_init(&ctx->cc_gc_chain); + spin_unlock(&sec_gc_ctx_list_lock); - LASSERT(ctx->cc_sec); - LASSERT(cfs_atomic_read(&ctx->cc_refcount) == 1); - CDEBUG(D_SEC, "gc pick up ctx %p(%u->%s)\n", - ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec)); - sptlrpc_cli_ctx_put(ctx, 1); + LASSERT(ctx->cc_sec); + LASSERT(atomic_read(&ctx->cc_refcount) == 1); + CDEBUG(D_SEC, "gc pick up ctx %p(%u->%s)\n", + ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec)); + sptlrpc_cli_ctx_put(ctx, 1); - cfs_spin_lock(&sec_gc_ctx_list_lock); - } + spin_lock(&sec_gc_ctx_list_lock); + } - cfs_spin_unlock(&sec_gc_ctx_list_lock); + spin_unlock(&sec_gc_ctx_list_lock); } static void sec_do_gc(struct ptlrpc_sec *sec) @@ -153,7 +146,7 @@ static void sec_do_gc(struct ptlrpc_sec *sec) LASSERT(sec->ps_policy->sp_cops->gc_ctx); if (unlikely(sec->ps_gc_next == 0)) { - CWARN("sec %p(%s) has 0 gc time\n", + CDEBUG(D_SEC, "sec %p(%s) has 0 gc time\n", sec, sec->ps_policy->sp_name); return; } @@ -169,110 +162,95 @@ static void sec_do_gc(struct ptlrpc_sec *sec) static int sec_gc_main(void *arg) { - struct ptlrpc_thread *thread = (struct ptlrpc_thread *) arg; - struct l_wait_info lwi; + struct ptlrpc_thread *thread = (struct ptlrpc_thread *) arg; + struct l_wait_info lwi; - cfs_daemonize_ctxt("sptlrpc_gc"); + unshare_fs_struct(); - /* Record that the thread is running */ - thread->t_flags = SVC_RUNNING; - cfs_waitq_signal(&thread->t_ctl_waitq); + /* Record that the thread is running */ + thread_set_flags(thread, SVC_RUNNING); + wake_up(&thread->t_ctl_waitq); - while (1) { - struct ptlrpc_sec *sec; + while (1) { + struct ptlrpc_sec *sec; - thread->t_flags &= ~SVC_SIGNAL; - sec_process_ctx_list(); + thread_clear_flags(thread, SVC_SIGNAL); + sec_process_ctx_list(); again: - /* go through sec list do gc. - * FIXME here we iterate through the whole list each time which - * is not optimal. we perhaps want to use balanced binary tree - * to trace each sec as order of expiry time. - * another issue here is we wakeup as fixed interval instead of - * according to each sec's expiry time */ - cfs_mutex_lock(&sec_gc_mutex); - cfs_list_for_each_entry(sec, &sec_gc_list, ps_gc_list) { - /* if someone is waiting to be deleted, let it - * proceed as soon as possible. */ - if (cfs_atomic_read(&sec_gc_wait_del)) { - CWARN("deletion pending, start over\n"); - cfs_mutex_unlock(&sec_gc_mutex); - goto again; - } - - sec_do_gc(sec); - } - cfs_mutex_unlock(&sec_gc_mutex); - - /* check ctx list again before sleep */ - sec_process_ctx_list(); - - lwi = LWI_TIMEOUT(SEC_GC_INTERVAL * CFS_HZ, NULL, NULL); - l_wait_event(thread->t_ctl_waitq, - thread->t_flags & (SVC_STOPPING | SVC_SIGNAL), - &lwi); - - if (thread->t_flags & SVC_STOPPING) { - thread->t_flags &= ~SVC_STOPPING; - break; - } - } - - thread->t_flags = SVC_STOPPED; - cfs_waitq_signal(&thread->t_ctl_waitq); - return 0; + /* go through sec list do gc. + * FIXME here we iterate through the whole list each time which + * is not optimal. we perhaps want to use balanced binary tree + * to trace each sec as order of expiry time. + * another issue here is we wakeup as fixed interval instead of + * according to each sec's expiry time */ + mutex_lock(&sec_gc_mutex); + list_for_each_entry(sec, &sec_gc_list, ps_gc_list) { + /* if someone is waiting to be deleted, let it + * proceed as soon as possible. */ + if (atomic_read(&sec_gc_wait_del)) { + CDEBUG(D_SEC, "deletion pending, start over\n"); + mutex_unlock(&sec_gc_mutex); + goto again; + } + + sec_do_gc(sec); + } + mutex_unlock(&sec_gc_mutex); + + /* check ctx list again before sleep */ + sec_process_ctx_list(); + + lwi = LWI_TIMEOUT(msecs_to_jiffies(SEC_GC_INTERVAL * + MSEC_PER_SEC), + NULL, NULL); + l_wait_event(thread->t_ctl_waitq, + thread_is_stopping(thread) || + thread_is_signal(thread), + &lwi); + + if (thread_test_and_clear_flags(thread, SVC_STOPPING)) + break; + } + + thread_set_flags(thread, SVC_STOPPED); + wake_up(&thread->t_ctl_waitq); + return 0; } int sptlrpc_gc_init(void) { - struct l_wait_info lwi = { 0 }; - int rc; - - cfs_mutex_init(&sec_gc_mutex); - cfs_spin_lock_init(&sec_gc_list_lock); - cfs_spin_lock_init(&sec_gc_ctx_list_lock); - - /* initialize thread control */ - memset(&sec_gc_thread, 0, sizeof(sec_gc_thread)); - cfs_waitq_init(&sec_gc_thread.t_ctl_waitq); - - rc = cfs_kernel_thread(sec_gc_main, &sec_gc_thread, - CLONE_VM | CLONE_FILES); - if (rc < 0) { - CERROR("can't start gc thread: %d\n", rc); - return rc; - } - - l_wait_event(sec_gc_thread.t_ctl_waitq, - sec_gc_thread.t_flags & SVC_RUNNING, &lwi); - return 0; -} + struct l_wait_info lwi = { 0 }; + struct task_struct *task; -void sptlrpc_gc_fini(void) -{ - struct l_wait_info lwi = { 0 }; + mutex_init(&sec_gc_mutex); + spin_lock_init(&sec_gc_list_lock); + spin_lock_init(&sec_gc_ctx_list_lock); - sec_gc_thread.t_flags = SVC_STOPPING; - cfs_waitq_signal(&sec_gc_thread.t_ctl_waitq); + INIT_LIST_HEAD(&sec_gc_list); + INIT_LIST_HEAD(&sec_gc_ctx_list); - l_wait_event(sec_gc_thread.t_ctl_waitq, - sec_gc_thread.t_flags & SVC_STOPPED, &lwi); -} + /* initialize thread control */ + memset(&sec_gc_thread, 0, sizeof(sec_gc_thread)); + init_waitqueue_head(&sec_gc_thread.t_ctl_waitq); -#else /* !__KERNEL__ */ + task = kthread_run(sec_gc_main, &sec_gc_thread, "sptlrpc_gc"); + if (IS_ERR(task)) { + CERROR("can't start gc thread: %ld\n", PTR_ERR(task)); + return PTR_ERR(task); + } -void sptlrpc_gc_add_sec(struct ptlrpc_sec *sec) -{ -} -void sptlrpc_gc_del_sec(struct ptlrpc_sec *sec) -{ -} -int sptlrpc_gc_init(void) -{ - return 0; + l_wait_event(sec_gc_thread.t_ctl_waitq, + thread_is_running(&sec_gc_thread), &lwi); + return 0; } + void sptlrpc_gc_fini(void) { -} + struct l_wait_info lwi = { 0 }; + + thread_set_flags(&sec_gc_thread, SVC_STOPPING); + wake_up(&sec_gc_thread.t_ctl_waitq); -#endif /* __KERNEL__ */ + l_wait_event(sec_gc_thread.t_ctl_waitq, + thread_is_stopped(&sec_gc_thread), &lwi); +}