X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fquota%2Fquota_check.c;h=70374f31ead1bcbea06be400a6155be2173b7beb;hb=774512ea1e17efb99713e29f4dff03c71843b211;hp=62fc1f0cfb697972299d0bfe96b9ae4e8915fd2e;hpb=d9eeca7c032d7f9290eb747c0058737fa2afb2ad;p=fs%2Flustre-release.git diff --git a/lustre/quota/quota_check.c b/lustre/quota/quota_check.c index 62fc1f0..70374f3 100644 --- a/lustre/quota/quota_check.c +++ b/lustre/quota/quota_check.c @@ -26,8 +26,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) 2011, 2012, Whamcloud, Inc. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -99,7 +101,7 @@ static int target_quotacheck_thread(void *data) struct lvfs_run_ctxt saved; int rc; - ptlrpc_daemonize("quotacheck"); + cfs_daemonize_ctxt("quotacheck"); exp = qta->qta_exp; obd = qta->qta_obd; @@ -114,9 +116,8 @@ static int target_quotacheck_thread(void *data) pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); rc = target_quotacheck_callback(exp, oqctl); - - atomic_inc(qta->qta_sem); - + class_export_put(exp); + cfs_up(qta->qta_sem); OBD_FREE_PTR(qta); return rc; } @@ -129,14 +130,11 @@ int target_quota_check(struct obd_device *obd, struct obd_export *exp, int rc = 0; ENTRY; - if (!atomic_dec_and_test(&obt->obt_quotachecking)) { - CDEBUG(D_INFO, "other people are doing quotacheck\n"); - GOTO(out, rc = -EBUSY); - } - OBD_ALLOC_PTR(qta); if (!qta) - GOTO(out, rc = -ENOMEM); + RETURN(ENOMEM); + + cfs_down(&obt->obt_quotachecking); qta->qta_exp = exp; qta->qta_obd = obd; @@ -145,146 +143,59 @@ int target_quota_check(struct obd_device *obd, struct obd_export *exp, qta->qta_sb = obt->obt_sb; qta->qta_sem = &obt->obt_quotachecking; + /* quotaoff firstly */ + oqctl->qc_cmd = Q_QUOTAOFF; if (!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME)) { + rc = do_mds_quota_off(obd, oqctl); + if (rc && rc != -EALREADY) { + CERROR("off quota on MDS failed: %d\n", rc); + GOTO(out, rc); + } + /* quota master */ rc = init_admin_quotafiles(obd, &qta->qta_oqctl); if (rc) { CERROR("init_admin_quotafiles failed: %d\n", rc); - OBD_FREE_PTR(qta); + GOTO(out, rc); + } + } else { + struct lvfs_run_ctxt saved; + struct lustre_quota_ctxt *qctxt = &obt->obt_qctxt; + + push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + rc = fsfilt_quotactl(obd, obt->obt_sb, oqctl); + pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + if (!rc) { + qctxt->lqc_flags &= ~UGQUOTA2LQC(oqctl->qc_type); + } else if (!quota_is_off(qctxt, oqctl)) { + CERROR("off quota on OSS failed: %d\n", rc); GOTO(out, rc); } } - rc = kernel_thread(target_quotacheck_thread, qta, CLONE_VM|CLONE_FILES); + /* we get ref for exp because target_quotacheck_callback() will use this + * export later b=18126 */ + class_export_get(exp); + rc = cfs_create_thread(target_quotacheck_thread, qta, + CFS_DAEMON_FLAGS); if (rc >= 0) { + /* target_quotacheck_thread will drop the ref on exp and release + * obt_quotachecking */ CDEBUG(D_INFO, "%s: target_quotacheck_thread: %d\n", obd->obd_name, rc); RETURN(0); + } else { + CERROR("%s: error starting quotacheck_thread: %d\n", + obd->obd_name, rc); + class_export_put(exp); + EXIT; } - CERROR("%s: error starting quotacheck_thread: %d\n", - obd->obd_name, rc); - OBD_FREE_PTR(qta); out: - atomic_inc(&obt->obt_quotachecking); - RETURN(rc); + cfs_up(&obt->obt_quotachecking); + OBD_FREE_PTR(qta); + return rc; } #endif /* __KERNEL__ */ #endif /* HAVE_QUOTA_SUPPORT */ - -int client_quota_check(struct obd_device *unused, struct obd_export *exp, - struct obd_quotactl *oqctl) -{ - struct client_obd *cli = &exp->exp_obd->u.cli; - struct ptlrpc_request *req; - struct obd_quotactl *body; - const struct req_format *rf; - int ver, opc, rc; - ENTRY; - - if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME)) { - rf = &RQF_MDS_QUOTACHECK; - ver = LUSTRE_MDS_VERSION; - opc = MDS_QUOTACHECK; - } else if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME)) { - rf = &RQF_OST_QUOTACHECK; - ver = LUSTRE_OST_VERSION; - opc = OST_QUOTACHECK; - } else { - RETURN(-EINVAL); - } - - req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), rf, ver, opc); - if (req == NULL) - RETURN(-ENOMEM); - - body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL); - *body = *oqctl; - - ptlrpc_request_set_replen(req); - - /* the next poll will find -ENODATA, that means quotacheck is - * going on */ - cli->cl_qchk_stat = -ENODATA; - rc = ptlrpc_queue_wait(req); - if (rc) - cli->cl_qchk_stat = rc; - ptlrpc_req_finished(req); - RETURN(rc); -} - -int client_quota_poll_check(struct obd_export *exp, struct if_quotacheck *qchk) -{ - struct client_obd *cli = &exp->exp_obd->u.cli; - int rc; - ENTRY; - - rc = cli->cl_qchk_stat; - - /* the client is not the previous one */ - if (rc == CL_NOT_QUOTACHECKED) - rc = -EINTR; - - qchk->obd_uuid = cli->cl_target_uuid; - /* FIXME change strncmp to strcmp and save the strlen op */ - if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME, - strlen(LUSTRE_OSC_NAME)) == 0) - memcpy(qchk->obd_type, LUSTRE_OST_NAME, - strlen(LUSTRE_OST_NAME)); - else if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME, - strlen(LUSTRE_MDC_NAME)) == 0) - memcpy(qchk->obd_type, LUSTRE_MDS_NAME, - strlen(LUSTRE_MDS_NAME)); - - RETURN(rc); -} - -int lmv_quota_check(struct obd_device *unused, struct obd_export *exp, - struct obd_quotactl *oqctl) -{ - struct obd_device *obd = class_exp2obd(exp); - struct lmv_obd *lmv = &obd->u.lmv; - struct lmv_tgt_desc *tgt; - int i, rc = 0; - ENTRY; - - for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) { - int err; - - if (!tgt->ltd_active) { - CERROR("lmv idx %d inactive\n", i); - RETURN(-EIO); - } - - err = obd_quotacheck(tgt->ltd_exp, oqctl); - if (err && !rc) - rc = err; - } - - RETURN(rc); -} - -int lov_quota_check(struct obd_device *unused, struct obd_export *exp, - struct obd_quotactl *oqctl) -{ - struct obd_device *obd = class_exp2obd(exp); - struct lov_obd *lov = &obd->u.lov; - int i, rc = 0; - ENTRY; - - for (i = 0; i < lov->desc.ld_tgt_count; i++) { - int err; - - if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) { - CERROR("lov idx %d inactive\n", i); - RETURN(-EIO); - } - - err = obd_quotacheck(lov->lov_tgts[i]->ltd_exp, oqctl); - if (err && !rc) - rc = err; - } - - RETURN(rc); -}