Whamcloud - gitweb
LU-1842 quota: setup/shutdown qmt device
[fs/lustre-release.git] / lustre / quota / qmt_internal.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
20  *
21  * GPL HEADER END
22  */
23 /*
24  * Copyright (c) 2012 Intel, Inc.
25  * Use is subject to license terms.
26  */
27
28 #include "lquota_internal.h"
29
30 #ifndef _QMT_INTERNAL_H
31 #define _QMT_INTERNAL_H
32
33 /*
34  * The Quota Master Target Device.
35  * The qmt is responsible for:
36  * - all interactions with MDT0 (provide request handlers, share ldlm namespace,
37  *   manage ldlm lvbo, ...)
38  * - all quota lock management (i.e. global quota locks as well as per-ID locks)
39  * - manage the quota pool configuration
40  *
41  * That's the structure MDT0 connects to in mdt_quota_init().
42  */
43 struct qmt_device {
44         /* Super-class. dt_device/lu_device for this master target */
45         struct dt_device        qmt_dt_dev;
46
47         /* service name of this qmt */
48         char                    qmt_svname[MAX_OBD_NAME];
49
50         /* Reference to the next device in the side stack
51          * The child device is actually the OSD device where we store the quota
52          * index files */
53         struct obd_export       *qmt_child_exp;
54         struct dt_device        *qmt_child;
55 };
56
57 /* Common data shared by qmt handlers */
58 struct qmt_thread_info {
59         union lquota_rec        qti_rec;
60         union lquota_id         qti_id;
61 };
62
63 extern struct lu_context_key qmt_thread_key;
64
65 /* helper function to extract qmt_thread_info from current environment */
66 static inline
67 struct qmt_thread_info *qmt_info(const struct lu_env *env)
68 {
69         struct qmt_thread_info  *info;
70
71         info = lu_context_key_get(&env->le_ctx, &qmt_thread_key);
72         if (info == NULL) {
73                 lu_env_refill((struct lu_env *)env);
74                 info = lu_context_key_get(&env->le_ctx, &qmt_thread_key);
75         }
76         LASSERT(info);
77         return info;
78 }
79
80 /* helper routine to convert a lu_device into a qmt_device */
81 static inline struct qmt_device *lu2qmt_dev(struct lu_device *ld)
82 {
83         return container_of0(lu2dt_dev(ld), struct qmt_device, qmt_dt_dev);
84 }
85
86 /* helper routine to convert a qmt_device into lu_device */
87 static inline struct lu_device *qmt2lu_dev(struct qmt_device *qmt)
88 {
89         return &qmt->qmt_dt_dev.dd_lu_dev;
90 }
91
92 /* qmt_lock.c */
93 int qmt_intent_policy(const struct lu_env *, struct lu_device *,
94                       struct ptlrpc_request *, struct ldlm_lock **, int);
95 int qmt_lvbo_init(struct lu_device *, struct ldlm_resource *);
96 int qmt_lvbo_update(struct lu_device *, struct ldlm_resource *,
97                     struct ptlrpc_request *, int);
98 int qmt_lvbo_size(struct lu_device *, struct ldlm_lock *);
99 int qmt_lvbo_fill(struct lu_device *, struct ldlm_lock *, void *, int);
100 int qmt_lvbo_free(struct lu_device *, struct ldlm_resource *);
101 #endif /* _QMT_INTERNAL_H */