X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fptlrpc%2Fptlrpcd.c;h=587f029bca707a5b0c45f96c3de6d227746b6274;hb=0152977c7d76f88d44223229c4982b9c6afd61ee;hp=687f58826aac1738bed252284849b30d375645c9;hpb=fc556b3fba16339d18ab84d7d2b7248db8eba8b3;p=fs%2Flustre-release.git diff --git a/lustre/ptlrpc/ptlrpcd.c b/lustre/ptlrpc/ptlrpcd.c index 687f588..587f029 100644 --- a/lustre/ptlrpc/ptlrpcd.c +++ b/lustre/ptlrpc/ptlrpcd.c @@ -1,128 +1,183 @@ /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * - * Copyright (C) 2001-2003 Cluster File Systems, Inc. - * Author Peter Braam + * GPL HEADER START * - * This file is part of Lustre, http://www.lustre.org. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Lustre is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. * - * Lustre is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). * - * You should have received a copy of the GNU General Public License - * along with Lustre; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * You should have received a copy of the GNU General Public License + * version 2 along with this program; If not, see + * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + * GPL HEADER END + */ +/* + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Use is subject to license terms. + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. + * + * lustre/ptlrpc/ptlrpcd.c */ #define DEBUG_SUBSYSTEM S_RPC #ifdef __KERNEL__ -# include -# include -# include -# include -# include -# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)) -# include -# include -# else -# include -# endif +# include #else /* __KERNEL__ */ # include -#endif - -#include -#include - -#ifndef __CYGWIN__ -# include -# include -#else # include #endif -#include -#include /* for OBD_FAIL_CHECK */ -#include - -#define LIOD_STOP 0 -struct ptlrpcd_ctl { - unsigned long pc_flags; - spinlock_t pc_lock; - struct completion pc_starting; - struct completion pc_finishing; - struct list_head pc_req_list; - wait_queue_head_t pc_waitq; - struct ptlrpc_request_set *pc_set; -#ifndef __KERNEL__ - int pc_recurred; - void *pc_callback; -#endif -}; +#include +#include +# include + +#include +#include /* for obd_zombie */ +#include /* for OBD_FAIL_CHECK */ +#include static struct ptlrpcd_ctl ptlrpcd_pc; static struct ptlrpcd_ctl ptlrpcd_recovery_pc; -static DECLARE_MUTEX(ptlrpcd_sem); +struct semaphore ptlrpcd_sem; static int ptlrpcd_users = 0; void ptlrpcd_wake(struct ptlrpc_request *req) { - struct ptlrpcd_ctl *pc = req->rq_ptlrpcd_data; + struct ptlrpc_request_set *rq_set = req->rq_set; - LASSERT(pc != NULL); + LASSERT(rq_set != NULL); - wake_up(&pc->pc_waitq); + cfs_waitq_signal(&rq_set->set_waitq); } -void ptlrpcd_add_req(struct ptlrpc_request *req) +/* + * Move all request from an existing request set to the ptlrpcd queue. + * All requests from the set must be in phase RQ_PHASE_NEW. + */ +void ptlrpcd_add_rqset(struct ptlrpc_request_set *set) +{ + struct list_head *tmp, *pos; + + list_for_each_safe(pos, tmp, &set->set_requests) { + struct ptlrpc_request *req = + list_entry(pos, struct ptlrpc_request, rq_set_chain); + + LASSERT(req->rq_phase == RQ_PHASE_NEW); + list_del_init(&req->rq_set_chain); + req->rq_set = NULL; + ptlrpcd_add_req(req); + atomic_dec(&set->set_remaining); + } + LASSERT(atomic_read(&set->set_remaining) == 0); +} +EXPORT_SYMBOL(ptlrpcd_add_rqset); + +/* + * Requests that are added to the ptlrpcd queue are sent via + * ptlrpcd_check->ptlrpc_check_set(). + */ +int ptlrpcd_add_req(struct ptlrpc_request *req) { struct ptlrpcd_ctl *pc; + int rc; + + spin_lock(&req->rq_lock); + if (req->rq_invalid_rqset) { + cfs_duration_t timeout; + struct l_wait_info lwi; + + req->rq_invalid_rqset = 0; + spin_unlock(&req->rq_lock); + + timeout = cfs_time_seconds(5); + lwi = LWI_TIMEOUT(timeout, back_to_sleep, NULL); + l_wait_event(req->rq_set_waitq, (req->rq_set == NULL), &lwi); + } else if (req->rq_set) { + LASSERT(req->rq_phase == RQ_PHASE_NEW); + LASSERT(req->rq_send_state == LUSTRE_IMP_REPLAY); + + /* ptlrpc_check_set will decrease the count */ + atomic_inc(&req->rq_set->set_remaining); + spin_unlock(&req->rq_lock); + + cfs_waitq_signal(&req->rq_set->set_waitq); + return 0; + } else { + spin_unlock(&req->rq_lock); + } if (req->rq_send_state == LUSTRE_IMP_FULL) pc = &ptlrpcd_pc; - else + else pc = &ptlrpcd_recovery_pc; + rc = ptlrpc_set_add_new_req(pc, req); + if (rc) { + /* + * Thread is probably in stop now so we need to + * kill this rpc as it was not added. Let's call + * interpret for it to let know we're killing it + * so that higher levels might free assosiated + * resources. + */ + + ptlrpc_req_interpret(req, -EBADR); + req->rq_set = NULL; + ptlrpc_req_finished(req); + } else if (req->rq_send_state == LUSTRE_IMP_CONNECTING) { + /* + * The request is for recovery, should be sent ASAP. + */ + cfs_waitq_signal(&pc->pc_set->set_waitq); + } - ptlrpc_set_add_new_req(pc->pc_set, req); - req->rq_ptlrpcd_data = pc; - - ptlrpcd_wake(req); + return rc; } static int ptlrpcd_check(struct ptlrpcd_ctl *pc) { struct list_head *tmp, *pos; struct ptlrpc_request *req; - unsigned long flags; int rc = 0; ENTRY; - if (test_bit(LIOD_STOP, &pc->pc_flags)) - RETURN(1); - - spin_lock_irqsave(&pc->pc_set->set_new_req_lock, flags); + spin_lock(&pc->pc_set->set_new_req_lock); list_for_each_safe(pos, tmp, &pc->pc_set->set_new_requests) { req = list_entry(pos, struct ptlrpc_request, rq_set_chain); list_del_init(&req->rq_set_chain); ptlrpc_set_add_req(pc->pc_set, req); - rc = 1; /* need to calculate its timeout */ + /* + * Need to calculate its timeout. + */ + rc = 1; } - spin_unlock_irqrestore(&pc->pc_set->set_new_req_lock, flags); + spin_unlock(&pc->pc_set->set_new_req_lock); - if (pc->pc_set->set_remaining) { + if (atomic_read(&pc->pc_set->set_remaining)) { rc = rc | ptlrpc_check_set(pc->pc_set); - /* XXX our set never completes, so we prune the completed - * reqs after each iteration. boy could this be smarter. */ + /* + * XXX: our set never completes, so we prune the completed + * reqs after each iteration. boy could this be smarter. + */ list_for_each_safe(pos, tmp, &pc->pc_set->set_requests) { req = list_entry(pos, struct ptlrpc_request, rq_set_chain); @@ -135,56 +190,82 @@ static int ptlrpcd_check(struct ptlrpcd_ctl *pc) } } + if (rc == 0) { + /* + * If new requests have been added, make sure to wake up. + */ + spin_lock(&pc->pc_set->set_new_req_lock); + rc = !list_empty(&pc->pc_set->set_new_requests); + spin_unlock(&pc->pc_set->set_new_req_lock); + } + RETURN(rc); } #ifdef __KERNEL__ -/* ptlrpc's code paths like to execute in process context, so we have this - * thread which spins on a set which contains the io rpcs. llite specifies - * ptlrpcd's set when it pushes pages down into the oscs */ +/* + * ptlrpc's code paths like to execute in process context, so we have this + * thread which spins on a set which contains the io rpcs. llite specifies + * ptlrpcd's set when it pushes pages down into the oscs. + */ static int ptlrpcd(void *arg) { struct ptlrpcd_ctl *pc = arg; - unsigned long flags; + int rc, exit = 0; ENTRY; - kportal_daemonize("ptlrpcd"); - - SIGNAL_MASK_LOCK(current, flags); - sigfillset(¤t->blocked); - RECALC_SIGPENDING; - SIGNAL_MASK_UNLOCK(current, flags); + if ((rc = cfs_daemonize_ctxt(pc->pc_name))) { + complete(&pc->pc_starting); + goto out; + } complete(&pc->pc_starting); - /* this mainloop strongly resembles ptlrpc_set_wait except - * that our set never completes. ptlrpcd_check calls ptlrpc_check_set - * when there are requests in the set. new requests come in - * on the set's new_req_list and ptlrpcd_check moves them into - * the set. */ - while (1) { - wait_queue_t set_wait; + /* + * This mainloop strongly resembles ptlrpc_set_wait() except that our + * set never completes. ptlrpcd_check() calls ptlrpc_check_set() when + * there are requests in the set. New requests come in on the set's + * new_req_list and ptlrpcd_check() moves them into the set. + */ + do { struct l_wait_info lwi; int timeout; - timeout = ptlrpc_set_next_timeout(pc->pc_set) * HZ; - lwi = LWI_TIMEOUT(timeout, ptlrpc_expired_set, pc->pc_set); + timeout = ptlrpc_set_next_timeout(pc->pc_set); + lwi = LWI_TIMEOUT(cfs_time_seconds(timeout ? timeout : 1), + ptlrpc_expired_set, pc->pc_set); - /* ala the pinger, wait on pc's waitqueue and the set's */ - init_waitqueue_entry(&set_wait, current); - add_wait_queue(&pc->pc_set->set_waitq, &set_wait); - l_wait_event(pc->pc_waitq, ptlrpcd_check(pc), &lwi); - remove_wait_queue(&pc->pc_set->set_waitq, &set_wait); + l_wait_event(pc->pc_set->set_waitq, ptlrpcd_check(pc), &lwi); - if (test_bit(LIOD_STOP, &pc->pc_flags)) - break; - } - /* wait for inflight requests to drain */ + /* + * Abort inflight rpcs for forced stop case. + */ + if (test_bit(LIOD_STOP, &pc->pc_flags)) { + if (test_bit(LIOD_FORCE, &pc->pc_flags)) + ptlrpc_abort_set(pc->pc_set); + exit++; + } + + /* + * Let's make one more loop to make sure that ptlrpcd_check() + * copied all raced new rpcs into the set so we can kill them. + */ + } while (exit < 2); + + /* + * Wait for inflight requests to drain. + */ if (!list_empty(&pc->pc_set->set_requests)) ptlrpc_set_wait(pc->pc_set); + complete(&pc->pc_finishing); +out: + clear_bit(LIOD_START, &pc->pc_flags); + clear_bit(LIOD_STOP, &pc->pc_flags); + clear_bit(LIOD_FORCE, &pc->pc_flags); return 0; } + #else int ptlrpcd_check_async_rpcs(void *arg) @@ -192,56 +273,98 @@ int ptlrpcd_check_async_rpcs(void *arg) struct ptlrpcd_ctl *pc = arg; int rc = 0; - /* single threaded!! */ + /* + * Single threaded!! + */ pc->pc_recurred++; - if (pc->pc_recurred == 1) + if (pc->pc_recurred == 1) { rc = ptlrpcd_check(pc); + if (!rc) + ptlrpc_expired_set(pc->pc_set); + /* + * XXX: send replay requests. + */ + if (pc == &ptlrpcd_recovery_pc) + rc = ptlrpcd_check(pc); + } pc->pc_recurred--; return rc; } + +int ptlrpcd_idle(void *arg) +{ + struct ptlrpcd_ctl *pc = arg; + + return (list_empty(&pc->pc_set->set_new_requests) && + atomic_read(&pc->pc_set->set_remaining) == 0); +} + #endif -static int ptlrpcd_start(struct ptlrpcd_ctl *pc) +int ptlrpcd_start(char *name, struct ptlrpcd_ctl *pc) { int rc = 0; + ENTRY; + + /* + * Do not allow start second thread for one pc. + */ + if (test_bit(LIOD_START, &pc->pc_flags)) { + CERROR("Starting second thread (%s) for same pc %p\n", + name, pc); + RETURN(-EALREADY); + } - memset(pc, 0, sizeof(*pc)); + set_bit(LIOD_START, &pc->pc_flags); init_completion(&pc->pc_starting); init_completion(&pc->pc_finishing); - init_waitqueue_head(&pc->pc_waitq); - pc->pc_flags = 0; spin_lock_init(&pc->pc_lock); - INIT_LIST_HEAD(&pc->pc_req_list); + strncpy(pc->pc_name, name, sizeof(pc->pc_name) - 1); pc->pc_set = ptlrpc_prep_set(); if (pc->pc_set == NULL) GOTO(out, rc = -ENOMEM); #ifdef __KERNEL__ - if (kernel_thread(ptlrpcd, pc, 0) < 0) { + rc = cfs_kernel_thread(ptlrpcd, pc, 0); + if (rc < 0) { ptlrpc_set_destroy(pc->pc_set); - GOTO(out, rc = -ECHILD); + GOTO(out, rc); } - + rc = 0; wait_for_completion(&pc->pc_starting); #else - pc->pc_callback = - liblustre_register_wait_callback(&ptlrpcd_check_async_rpcs, pc); + pc->pc_wait_callback = + liblustre_register_wait_callback("ptlrpcd_check_async_rpcs", + &ptlrpcd_check_async_rpcs, pc); + pc->pc_idle_callback = + liblustre_register_idle_callback("ptlrpcd_check_idle_rpcs", + &ptlrpcd_idle, pc); #endif out: + if (rc) + clear_bit(LIOD_START, &pc->pc_flags); RETURN(rc); } -static void ptlrpcd_stop(struct ptlrpcd_ctl *pc) +void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force) { + if (!test_bit(LIOD_START, &pc->pc_flags)) { + CERROR("Thread for pc %p was not started\n", pc); + return; + } + set_bit(LIOD_STOP, &pc->pc_flags); - wake_up(&pc->pc_waitq); + if (force) + set_bit(LIOD_FORCE, &pc->pc_flags); + cfs_waitq_signal(&pc->pc_set->set_waitq); #ifdef __KERNEL__ wait_for_completion(&pc->pc_finishing); #else - liblustre_deregister_wait_callback(pc->pc_callback); + liblustre_deregister_wait_callback(pc->pc_wait_callback); + liblustre_deregister_idle_callback(pc->pc_idle_callback); #endif ptlrpc_set_destroy(pc->pc_set); } @@ -251,33 +374,33 @@ int ptlrpcd_addref(void) int rc = 0; ENTRY; - down(&ptlrpcd_sem); + mutex_down(&ptlrpcd_sem); if (++ptlrpcd_users != 1) GOTO(out, rc); - rc = ptlrpcd_start(&ptlrpcd_pc); + rc = ptlrpcd_start("ptlrpcd", &ptlrpcd_pc); if (rc) { --ptlrpcd_users; GOTO(out, rc); } - rc = ptlrpcd_start(&ptlrpcd_recovery_pc); + rc = ptlrpcd_start("ptlrpcd-recov", &ptlrpcd_recovery_pc); if (rc) { - ptlrpcd_stop(&ptlrpcd_pc); + ptlrpcd_stop(&ptlrpcd_pc, 0); --ptlrpcd_users; GOTO(out, rc); } out: - up(&ptlrpcd_sem); + mutex_up(&ptlrpcd_sem); RETURN(rc); } void ptlrpcd_decref(void) { - down(&ptlrpcd_sem); + mutex_down(&ptlrpcd_sem); if (--ptlrpcd_users == 0) { - ptlrpcd_stop(&ptlrpcd_pc); - ptlrpcd_stop(&ptlrpcd_recovery_pc); + ptlrpcd_stop(&ptlrpcd_pc, 0); + ptlrpcd_stop(&ptlrpcd_recovery_pc, 0); } - up(&ptlrpcd_sem); + mutex_up(&ptlrpcd_sem); }