4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 021110-1307, USA
24 * Copyright (c) 2012 Intel, Inc.
25 * Use is subject to license terms.
27 * Author: Johann Lombardi <johann.lombardi@intel.com>
28 * Author: Niu Yawei <yawei.niu@intel.com>
32 * Quota Slave Driver (QSD) management.
34 * The quota slave feature is implemented under the form of a library called
35 * QSD. Each OSD device should create a QSD instance via qsd_init() which will
36 * be used to manage quota enforcement for this device. This implies:
37 * - completing the reintegration procedure with the quota master (aka QMT, see
38 * qmt_dev.c) to retrieve the latest quota settings and space distribution.
39 * - managing quota locks in order to be notified of configuration changes.
40 * - acquiring space from the QMT when quota space for a given user/group is
41 * close to exhaustion.
42 * - allocating quota space to service threads for local request processing.
44 * Once the QSD instance created, the OSD device should invoke qsd_start()
45 * when recovery is completed. This notifies the QSD that we are about to
46 * process new requests on which quota should be strictly enforced.
47 * Then, qsd_op_begin/end can be used to reserve/release/pre-acquire quota space
48 * for/after each operation until shutdown where the QSD instance should be
49 * freed via qsd_fini().
53 # define EXPORT_SYMTAB
56 #define DEBUG_SUBSYSTEM S_LQUOTA
58 #include <obd_class.h>
59 #include "qsd_internal.h"
61 cfs_mem_cache_t *upd_kmem;
63 struct lu_kmem_descr qsd_caches[] = {
65 .ckd_cache = &upd_kmem,
66 .ckd_name = "upd_kmem",
67 .ckd_size = sizeof(struct qsd_upd_rec)
74 /* define qsd thread key */
75 LU_KEY_INIT_FINI(qsd, struct qsd_thread_info);
76 LU_CONTEXT_KEY_DEFINE(qsd, LCT_MD_THREAD | LCT_DT_THREAD | LCT_LOCAL);
77 LU_KEY_INIT_GENERIC(qsd);
79 /* some procfs helpers */
80 static int lprocfs_qsd_rd_state(char *page, char **start, off_t off,
81 int count, int *eof, void *data)
83 struct qsd_instance *qsd = (struct qsd_instance *)data;
89 memset(enabled, 0, sizeof(enabled));
90 if (qsd_type_enabled(qsd, USRQUOTA))
92 if (qsd_type_enabled(qsd, GRPQUOTA))
94 if (strlen(enabled) == 0)
95 strcat(enabled, "none");
97 rc = snprintf(page, count,
101 "quota enabled: %s\n"
102 "conn to master: %s\n",
103 qsd->qsd_svname, qsd->qsd_pool_id,
104 qsd->qsd_is_md ? "md" : "dt", enabled,
105 qsd->qsd_exp_valid ? "setup" : "not setup yet");
107 if (qsd->qsd_prepared)
108 rc += snprintf(page + rc, count - rc,
109 "user uptodate: glb[%d],slv[%d],reint[%d]\n"
110 "group uptodate: glb[%d],slv[%d],reint[%d]\n",
111 qsd->qsd_type_array[USRQUOTA]->qqi_glb_uptodate,
112 qsd->qsd_type_array[USRQUOTA]->qqi_slv_uptodate,
113 qsd->qsd_type_array[USRQUOTA]->qqi_reint,
114 qsd->qsd_type_array[GRPQUOTA]->qqi_glb_uptodate,
115 qsd->qsd_type_array[GRPQUOTA]->qqi_slv_uptodate,
116 qsd->qsd_type_array[GRPQUOTA]->qqi_reint);
120 static int lprocfs_qsd_rd_enabled(char *page, char **start, off_t off,
121 int count, int *eof, void *data)
123 struct qsd_instance *qsd = (struct qsd_instance *)data;
126 LASSERT(qsd != NULL);
128 memset(enabled, 0, sizeof(enabled));
129 if (qsd_type_enabled(qsd, USRQUOTA))
130 strcat(enabled, "u");
131 if (qsd_type_enabled(qsd, GRPQUOTA))
132 strcat(enabled, "g");
133 if (strlen(enabled) == 0)
134 strcat(enabled, "none");
136 return snprintf(page, count, "%s\n", enabled);
139 /* force reintegration procedure to be executed.
140 * Used for test/debugging purpose */
141 static int lprocfs_qsd_wr_force_reint(struct file *file, const char *buffer,
142 unsigned long count, void *data)
144 struct qsd_instance *qsd = (struct qsd_instance *)data;
147 LASSERT(qsd != NULL);
149 write_lock(&qsd->qsd_lock);
150 if (qsd->qsd_stopping) {
151 /* don't mess up with shutdown procedure, it is already
152 * complicated enough */
154 } else if (!qsd->qsd_prepared) {
157 /* mark all indexes as stale */
158 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++) {
159 qsd->qsd_type_array[qtype]->qqi_glb_uptodate = false;
160 qsd->qsd_type_array[qtype]->qqi_slv_uptodate = false;
163 write_unlock(&qsd->qsd_lock);
168 /* kick off reintegration */
169 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++) {
170 rc = qsd_start_reint_thread(qsd->qsd_type_array[qtype]);
174 return rc == 0 ? count : rc;
177 static int lprocfs_qsd_rd_timeout(char *page, char **start, off_t off,
178 int count, int *eof, void *data)
180 struct qsd_instance *qsd = (struct qsd_instance *)data;
181 LASSERT(qsd != NULL);
183 return snprintf(page, count, "%d\n", qsd_wait_timeout(qsd));
186 static int lprocfs_qsd_wr_timeout(struct file *file, const char *buffer,
187 unsigned long count, void *data)
189 struct qsd_instance *qsd = (struct qsd_instance *)data;
191 LASSERT(qsd != NULL);
193 rc = lprocfs_write_helper(buffer, count, &timeout);
199 qsd->qsd_timeout = timeout;
203 static struct lprocfs_vars lprocfs_quota_qsd_vars[] = {
204 { "info", lprocfs_qsd_rd_state, 0, 0},
205 { "enabled", lprocfs_qsd_rd_enabled, 0, 0},
206 { "force_reint", 0, lprocfs_qsd_wr_force_reint, 0},
207 { "timeout", lprocfs_qsd_rd_timeout, lprocfs_qsd_wr_timeout, 0},
212 * Callback function invoked by the OSP layer when the connection to the master
215 * \param data - is a pointer to the qsd_instance
217 * \retval - 0 on success, appropriate error on failure
219 static int qsd_conn_callback(void *data)
221 struct qsd_instance *qsd = (struct qsd_instance *)data;
225 /* qsd_exp should now be valid */
226 LASSERT(qsd->qsd_exp);
228 /* grab reference on namespace */
229 ldlm_namespace_get(class_exp2obd(qsd->qsd_exp)->obd_namespace);
230 qsd->qsd_ns = class_exp2obd(qsd->qsd_exp)->obd_namespace;
232 write_lock(&qsd->qsd_lock);
233 /* notify that qsd_exp is now valid */
234 qsd->qsd_exp_valid = true;
235 write_unlock(&qsd->qsd_lock);
237 /* Now that the connection to master is setup, we can initiate the
238 * reintegration procedure for quota types which are enabled.
239 * It is worth noting that, if the qsd_instance hasn't been started
240 * already, then we can only complete the first two steps of the
241 * reintegration procedure (i.e. global lock enqueue and slave
242 * index transfer) since the space usage reconciliation (i.e.
243 * step 3) will have to wait for qsd_start() to be called */
244 for (type = USRQUOTA; type < MAXQUOTAS; type++) {
245 struct qsd_qtype_info *qqi = qsd->qsd_type_array[type];
246 cfs_waitq_signal(&qqi->qqi_reint_thread.t_ctl_waitq);
253 * Release qsd_qtype_info structure which contains data associated with a
254 * given quota type. This releases the accounting objects.
255 * It's called on OSD cleanup when the qsd instance is released.
257 * \param env - is the environment passed by the caller
258 * \param qsd - is the qsd instance managing the qsd_qtype_info structure
260 * \param qtype - is the quota type to be shutdown
262 static void qsd_qtype_fini(const struct lu_env *env, struct qsd_instance *qsd,
265 struct qsd_qtype_info *qqi;
268 if (qsd->qsd_type_array[qtype] == NULL)
270 qqi = qsd->qsd_type_array[qtype];
271 qsd->qsd_type_array[qtype] = NULL;
273 /* all deferred work lists should be empty */
274 LASSERT(cfs_list_empty(&qqi->qqi_deferred_glb));
275 LASSERT(cfs_list_empty(&qqi->qqi_deferred_slv));
277 /* shutdown lquota site */
278 if (qqi->qqi_site != NULL && !IS_ERR(qqi->qqi_site)) {
279 lquota_site_free(env, qqi->qqi_site);
280 qqi->qqi_site = NULL;
283 /* by now, all qqi users should have gone away */
284 LASSERT(cfs_atomic_read(&qqi->qqi_ref) == 1);
285 lu_ref_fini(&qqi->qqi_reference);
287 /* release accounting object */
288 if (qqi->qqi_acct_obj != NULL && !IS_ERR(qqi->qqi_acct_obj)) {
289 lu_object_put(env, &qqi->qqi_acct_obj->do_lu);
290 qqi->qqi_acct_obj = NULL;
293 /* release slv index */
294 if (qqi->qqi_slv_obj != NULL && !IS_ERR(qqi->qqi_slv_obj)) {
295 lu_object_put(env, &qqi->qqi_slv_obj->do_lu);
296 qqi->qqi_slv_obj = NULL;
297 qqi->qqi_slv_ver = 0;
300 /* release global index */
301 if (qqi->qqi_glb_obj != NULL && !IS_ERR(qqi->qqi_glb_obj)) {
302 lu_object_put(env, &qqi->qqi_glb_obj->do_lu);
303 qqi->qqi_glb_obj = NULL;
304 qqi->qqi_glb_ver = 0;
312 * Allocate and initialize a qsd_qtype_info structure for quota type \qtype.
313 * This opens the accounting object and initializes the proc file.
314 * It's called on OSD start when the qsd_prepare() is invoked on the qsd
317 * \param env - the environment passed by the caller
318 * \param qsd - is the qsd instance which will be in charge of the new
319 * qsd_qtype_info instance.
320 * \param qtype - is quota type to set up
322 * \retval - 0 on success and qsd->qsd_type_array[qtype] is allocated,
323 * appropriate error on failure
325 static int qsd_qtype_init(const struct lu_env *env, struct qsd_instance *qsd,
328 struct qsd_qtype_info *qqi;
330 struct obd_uuid uuid;
333 LASSERT(qsd->qsd_type_array[qtype] == NULL);
335 /* allocate structure for this quota type */
339 qsd->qsd_type_array[qtype] = qqi;
340 cfs_atomic_set(&qqi->qqi_ref, 1); /* referenced from qsd */
342 /* set backpointer and other parameters */
344 qqi->qqi_qtype = qtype;
345 lu_ref_init(&qqi->qqi_reference);
346 lquota_generate_fid(&qqi->qqi_fid, qsd->qsd_pool_id, QSD_RES_TYPE(qsd),
348 qqi->qqi_glb_uptodate = false;
349 qqi->qqi_slv_uptodate = false;
350 qqi->qqi_reint = false;
351 cfs_waitq_init(&qqi->qqi_reint_thread.t_ctl_waitq);
352 thread_set_flags(&qqi->qqi_reint_thread, SVC_STOPPED);
353 CFS_INIT_LIST_HEAD(&qqi->qqi_deferred_glb);
354 CFS_INIT_LIST_HEAD(&qqi->qqi_deferred_slv);
355 memset(&qqi->qqi_lockh, 0, sizeof(qqi->qqi_lockh));
357 /* open accounting object */
358 LASSERT(qqi->qqi_acct_obj == NULL);
359 qqi->qqi_acct_obj = acct_obj_lookup(env, qsd->qsd_dev, qtype);
360 if (qqi->qqi_acct_obj == NULL) {
361 LCONSOLE_ERROR("%s: No %s space accounting support. Please use "
362 "tunefs.lustre --quota option to enable quota "
364 qsd->qsd_svname, QTYPE_NAME(qtype));
365 GOTO(out, rc = -ENOENT);
368 /* open global index copy */
369 LASSERT(qqi->qqi_glb_obj == NULL);
370 qqi->qqi_glb_obj = lquota_disk_glb_find_create(env, qsd->qsd_dev,
372 &qqi->qqi_fid, true);
373 if (IS_ERR(qqi->qqi_glb_obj)) {
374 CERROR("%s: can't open global index copy "DFID" %ld\n",
375 qsd->qsd_svname, PFID(&qqi->qqi_fid),
376 PTR_ERR(qqi->qqi_glb_obj));
377 GOTO(out, rc = PTR_ERR(qqi->qqi_glb_obj));
379 qqi->qqi_glb_ver = dt_version_get(env, qqi->qqi_glb_obj);
381 /* open slave index copy */
382 LASSERT(qqi->qqi_slv_obj == NULL);
383 obd_str2uuid(&uuid, qsd->qsd_svname);
384 qqi->qqi_slv_obj = lquota_disk_slv_find_create(env, qsd->qsd_dev,
386 &qqi->qqi_fid, &uuid,
388 if (IS_ERR(qqi->qqi_slv_obj)) {
389 CERROR("%s: can't open slave index copy "DFID" %ld\n",
390 qsd->qsd_svname, PFID(&qqi->qqi_fid),
391 PTR_ERR(qqi->qqi_slv_obj));
392 GOTO(out, rc = PTR_ERR(qqi->qqi_slv_obj));
394 qqi->qqi_slv_ver = dt_version_get(env, qqi->qqi_slv_obj);
397 qqi->qqi_site = lquota_site_alloc(env, qqi, false, qtype, &qsd_lqe_ops);
398 if (IS_ERR(qqi->qqi_site)) {
399 CERROR("%s: can't allocate site "DFID" %ld\n", qsd->qsd_svname,
400 PFID(&qqi->qqi_fid), PTR_ERR(qqi->qqi_site));
401 GOTO(out, rc = PTR_ERR(qqi->qqi_site));
404 /* register proc entry for accounting & global index copy objects */
405 rc = lprocfs_seq_create(qsd->qsd_proc,
406 qtype == USRQUOTA ? "acct_user" : "acct_group",
407 0444, &lprocfs_quota_seq_fops,
410 CERROR("%s: can't add procfs entry for accounting file %d\n",
411 qsd->qsd_svname, rc);
415 rc = lprocfs_seq_create(qsd->qsd_proc,
416 qtype == USRQUOTA ? "limit_user" : "limit_group",
417 0444, &lprocfs_quota_seq_fops,
420 CERROR("%s: can't add procfs entry for global index copy %d\n",
421 qsd->qsd_svname, rc);
427 qsd_qtype_fini(env, qsd, qtype);
432 * Release a qsd_instance. Companion of qsd_init(). This releases all data
433 * structures associated with the quota slave (on-disk objects, lquota entry
435 * This function should be called when the OSD is shutting down.
437 * \param env - is the environment passed by the caller
438 * \param qsd - is the qsd instance to shutdown
440 void qsd_fini(const struct lu_env *env, struct qsd_instance *qsd)
445 if (unlikely(qsd == NULL))
448 CDEBUG(D_QUOTA, "%s: initiating QSD shutdown\n", qsd->qsd_svname);
449 write_lock(&qsd->qsd_lock);
450 qsd->qsd_stopping = true;
451 write_unlock(&qsd->qsd_lock);
453 /* remove from the list of fsinfo */
454 if (!cfs_list_empty(&qsd->qsd_link)) {
455 LASSERT(qsd->qsd_fsinfo != NULL);
456 down(&qsd->qsd_fsinfo->qfs_sem);
457 cfs_list_del_init(&qsd->qsd_link);
458 up(&qsd->qsd_fsinfo->qfs_sem);
461 /* remove qsd proc entry */
462 if (qsd->qsd_proc != NULL) {
463 lprocfs_remove(&qsd->qsd_proc);
464 qsd->qsd_proc = NULL;
467 /* stop the writeback thread */
468 qsd_stop_upd_thread(qsd);
470 /* shutdown the reintegration threads */
471 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++) {
472 if (qsd->qsd_type_array[qtype] == NULL)
474 qsd_stop_reint_thread(qsd->qsd_type_array[qtype]);
477 /* release reference on namespace */
478 if (qsd->qsd_ns != NULL) {
479 ldlm_namespace_put(qsd->qsd_ns);
483 /* free per-quota type data */
484 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++)
485 qsd_qtype_fini(env, qsd, qtype);
487 /* deregister connection to the quota master */
488 qsd->qsd_exp_valid = false;
489 lustre_deregister_osp_item(&qsd->qsd_exp);
491 /* release per-filesystem information */
492 if (qsd->qsd_fsinfo != NULL)
493 qsd_put_fsinfo(qsd->qsd_fsinfo);
495 /* release quota root directory */
496 if (qsd->qsd_root != NULL) {
497 lu_object_put(env, &qsd->qsd_root->do_lu);
498 qsd->qsd_root = NULL;
501 /* release reference on dt_device */
502 if (qsd->qsd_dev != NULL) {
503 lu_ref_del(&qsd->qsd_dev->dd_lu_dev.ld_reference, "qsd", qsd);
504 lu_device_put(&qsd->qsd_dev->dd_lu_dev);
508 CDEBUG(D_QUOTA, "%s: QSD shutdown completed\n", qsd->qsd_svname);
512 EXPORT_SYMBOL(qsd_fini);
515 * Create a new qsd_instance to be associated with backend osd device
516 * identified by \dev.
518 * \param env - the environment passed by the caller
519 * \param svname - is the service name of the OSD device creating this instance
520 * \param dev - is the dt_device where to store quota index files
521 * \param osd_proc - is the procfs parent directory where to create procfs file
522 * related to this new qsd instance
524 * \retval - pointer to new qsd_instance associated with dev \dev on success,
525 * appropriate error on failure
527 struct qsd_instance *qsd_init(const struct lu_env *env, char *svname,
528 struct dt_device *dev,
529 cfs_proc_dir_entry_t *osd_proc)
531 struct qsd_thread_info *qti = qsd_info(env);
532 struct qsd_instance *qsd;
536 /* only configure qsd for MDT & OST */
537 type = server_name2index(svname, &idx, NULL);
538 if (type != LDD_F_SV_TYPE_MDT && type != LDD_F_SV_TYPE_OST)
541 /* allocate qsd instance */
544 RETURN(ERR_PTR(-ENOMEM));
546 /* generic initializations */
547 rwlock_init(&qsd->qsd_lock);
548 CFS_INIT_LIST_HEAD(&qsd->qsd_link);
549 thread_set_flags(&qsd->qsd_upd_thread, SVC_STOPPED);
550 cfs_waitq_init(&qsd->qsd_upd_thread.t_ctl_waitq);
551 CFS_INIT_LIST_HEAD(&qsd->qsd_upd_list);
552 spin_lock_init(&qsd->qsd_adjust_lock);
553 CFS_INIT_LIST_HEAD(&qsd->qsd_adjust_list);
554 qsd->qsd_prepared = false;
555 qsd->qsd_started = false;
557 /* copy service name */
558 strncpy(qsd->qsd_svname, svname, MAX_OBD_NAME);
560 /* grab reference on osd device */
561 lu_device_get(&dev->dd_lu_dev);
562 lu_ref_add(&dev->dd_lu_dev.ld_reference, "qsd", qsd);
565 /* we only support pool ID 0 (default data or metadata pool) for the
566 * time being. A different pool ID could be assigned to this target via
567 * the configuration log in the future */
568 qsd->qsd_pool_id = 0;
570 /* get fsname from svname */
571 rc = server_name2fsname(svname, qti->qti_buf, NULL);
573 CERROR("%s: fail to extract filesystem name\n", svname);
577 /* look up quota setting for the filesystem the target belongs to */
578 qsd->qsd_fsinfo = qsd_get_fsinfo(qti->qti_buf, 1);
579 if (qsd->qsd_fsinfo == NULL) {
580 CERROR("%s: failed to locate filesystem information\n", svname);
581 GOTO(out, rc = -EINVAL);
584 /* add in the list of lquota_fsinfo */
585 down(&qsd->qsd_fsinfo->qfs_sem);
586 list_add_tail(&qsd->qsd_link, &qsd->qsd_fsinfo->qfs_qsd_list);
587 up(&qsd->qsd_fsinfo->qfs_sem);
589 /* register procfs directory */
590 qsd->qsd_proc = lprocfs_register(QSD_DIR, osd_proc,
591 lprocfs_quota_qsd_vars, qsd);
592 if (IS_ERR(qsd->qsd_proc)) {
593 rc = PTR_ERR(qsd->qsd_proc);
594 qsd->qsd_proc = NULL;
595 CERROR("%s: fail to create quota slave proc entry (%d)\n",
607 EXPORT_SYMBOL(qsd_init);
610 * Initialize on-disk structures in order to manage quota enforcement for
611 * the target associated with the qsd instance \qsd and starts the reintegration
612 * procedure for each quota type as soon as possible.
613 * The last step of the reintegration will be completed once qsd_start() is
614 * called, at which points the space reconciliation with the master will be
616 * This function must be called when the server stack is fully configured,
617 * typically when ->ldo_prepare is called across the stack.
619 * \param env - the environment passed by the caller
620 * \param qsd - is qsd_instance to prepare
622 * \retval - 0 on success, appropriate error on failure
624 int qsd_prepare(const struct lu_env *env, struct qsd_instance *qsd)
626 struct qsd_thread_info *qti = qsd_info(env);
630 if (unlikely(qsd == NULL))
633 read_lock(&qsd->qsd_lock);
634 if (qsd->qsd_prepared) {
635 CERROR("%s: qsd instance already prepared\n", qsd->qsd_svname);
638 read_unlock(&qsd->qsd_lock);
642 /* Record whether this qsd instance is managing quota enforcement for a
643 * MDT (i.e. inode quota) or OST (block quota) */
644 if (lu_device_is_md(qsd->qsd_dev->dd_lu_dev.ld_site->ls_top_dev)) {
645 qsd->qsd_is_md = true;
646 qsd->qsd_sync_threshold = LQUOTA_LEAST_QUNIT(LQUOTA_RES_MD);
648 qsd->qsd_sync_threshold = LQUOTA_LEAST_QUNIT(LQUOTA_RES_DT);
651 /* look-up on-disk directory for the quota slave */
652 qsd->qsd_root = lquota_disk_dir_find_create(env, qsd->qsd_dev, NULL,
654 if (IS_ERR(qsd->qsd_root)) {
655 rc = PTR_ERR(qsd->qsd_root);
656 qsd->qsd_root = NULL;
657 CERROR("%s: failed to create quota slave root dir (%d)\n",
658 qsd->qsd_svname, rc);
662 /* initialize per-quota type data */
663 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++) {
664 rc = qsd_qtype_init(env, qsd, qtype);
669 /* pools successfully setup, mark the qsd as prepared */
670 write_lock(&qsd->qsd_lock);
671 qsd->qsd_prepared = true;
672 write_unlock(&qsd->qsd_lock);
674 /* start reintegration thread for each type, if required */
675 for (qtype = USRQUOTA; qtype < MAXQUOTAS; qtype++) {
676 struct qsd_qtype_info *qqi = qsd->qsd_type_array[qtype];
678 rc = qsd_start_reint_thread(qqi);
680 CERROR("%s: failed to start reint thread for type %s "
681 "(%d)\n", qsd->qsd_svname, QTYPE_NAME(qtype),
687 /* start writeback thread */
688 rc = qsd_start_upd_thread(qsd);
690 CERROR("%s: failed to start writeback thread (%d)\n",
691 qsd->qsd_svname, rc);
695 /* generate osp name */
696 rc = tgt_name2ospname((char *)qsd->qsd_svname, qti->qti_buf);
698 CERROR("%s: failed to generate ospname (%d)\n",
699 qsd->qsd_svname, rc);
703 /* the connection callback will start the reintegration
704 * procedure if quota is enabled */
705 rc = lustre_register_osp_item(qti->qti_buf, &qsd->qsd_exp,
706 qsd_conn_callback, (void *)qsd);
708 CERROR("%s: fail to get connection to master (%d)\n",
709 qsd->qsd_svname, rc);
715 EXPORT_SYMBOL(qsd_prepare);
718 * Start a qsd instance. This will complete the last step of the reintegration
719 * procedure as soon as possible (provided that the master is reachable).
720 * This should be called when recovery has been completed and quota should now
721 * be enforced on every operations.
723 * \param env - the environment passed by the caller
724 * \param qsd - is the qsd instance associated with the osd device to start
726 int qsd_start(const struct lu_env *env, struct qsd_instance *qsd)
731 if (unlikely(qsd == NULL))
734 write_lock(&qsd->qsd_lock);
735 if (!qsd->qsd_prepared) {
736 CERROR("%s: can't start qsd instance since it was properly "
737 "initialized\n", qsd->qsd_svname);
739 } else if (qsd->qsd_started) {
740 CERROR("%s: qsd instance already started\n", qsd->qsd_svname);
743 /* notify that the qsd_instance is now started */
744 qsd->qsd_started = true;
746 write_unlock(&qsd->qsd_lock);
751 /* Trigger the 3rd step of reintegration: If usage > granted, acquire
752 * up to usage; If usage < granted, release down to usage. */
753 for (type = USRQUOTA; type < MAXQUOTAS; type++) {
754 struct qsd_qtype_info *qqi = qsd->qsd_type_array[type];
755 cfs_waitq_signal(&qqi->qqi_reint_thread.t_ctl_waitq);
760 EXPORT_SYMBOL(qsd_start);
762 void lustre_register_quota_process_config(int (*qpc)(struct lustre_cfg *lcfg));
765 * Global initialization performed at module load time
767 int qsd_glb_init(void)
771 rc = lu_kmem_init(qsd_caches);
775 qsd_key_init_generic(&qsd_thread_key, NULL);
776 lu_context_key_register(&qsd_thread_key);
777 lustre_register_quota_process_config(qsd_process_config);
783 * Companion of qsd_glb_init() called at module unload time
785 void qsd_glb_fini(void)
787 lustre_register_quota_process_config(NULL);
788 lu_kmem_fini(qsd_caches);
789 lu_context_key_degister(&qsd_thread_key);