linux/drivers/staging/lustre/lustre/include/lustre_quota.h
<<
>>
Prefs
   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) 2011, 2012, Intel Corporation.
  25 * Use is subject to license terms.
  26 */
  27
  28#ifndef _LUSTRE_QUOTA_H
  29#define _LUSTRE_QUOTA_H
  30
  31/** \defgroup quota quota
  32 *
  33 */
  34
  35#include <linux/lustre_quota.h>
  36
  37#include <dt_object.h>
  38#include <lustre_fid.h>
  39#include <lustre_dlm.h>
  40
  41#ifndef MAX_IQ_TIME
  42#define MAX_IQ_TIME  604800     /* (7*24*60*60) 1 week */
  43#endif
  44
  45#ifndef MAX_DQ_TIME
  46#define MAX_DQ_TIME  604800     /* (7*24*60*60) 1 week */
  47#endif
  48
  49struct lquota_id_info;
  50struct lquota_trans;
  51
  52/* Gather all quota record type in an union that can be used to read any records
  53 * from disk. All fields of these records must be 64-bit aligned, otherwise the
  54 * OSD layer may swab them incorrectly. */
  55union lquota_rec {
  56        struct lquota_glb_rec   lqr_glb_rec;
  57        struct lquota_slv_rec   lqr_slv_rec;
  58        struct lquota_acct_rec  lqr_acct_rec;
  59};
  60
  61/* Index features supported by the global index objects
  62 * Only used for migration purpose and should be removed once on-disk migration
  63 * is no longer needed */
  64extern struct dt_index_features dt_quota_iusr_features;
  65extern struct dt_index_features dt_quota_busr_features;
  66extern struct dt_index_features dt_quota_igrp_features;
  67extern struct dt_index_features dt_quota_bgrp_features;
  68
  69/* Name used in the configuration logs to identify the default metadata pool
  70 * (composed of all the MDTs, with pool ID 0) and the default data pool (all
  71 * the OSTs, with pool ID 0 too). */
  72#define QUOTA_METAPOOL_NAME   "mdt="
  73#define QUOTA_DATAPOOL_NAME   "ost="
  74
  75/*
  76 * Quota Master Target support
  77 */
  78
  79/* Request handlers for quota master operations.
  80 * This is used by the MDT to pass quota/lock requests to the quota master
  81 * target. This won't be needed any more once the QMT is a real target and
  82 * does not rely any more on the MDT service threads and namespace. */
  83struct qmt_handlers {
  84        /* Handle quotactl request from client. */
  85        int (*qmth_quotactl)(const struct lu_env *, struct lu_device *,
  86                             struct obd_quotactl *);
  87
  88        /* Handle dqacq/dqrel request from slave. */
  89        int (*qmth_dqacq)(const struct lu_env *, struct lu_device *,
  90                          struct ptlrpc_request *);
  91
  92        /* LDLM intent policy associated with quota locks */
  93        int (*qmth_intent_policy)(const struct lu_env *, struct lu_device *,
  94                                  struct ptlrpc_request *, struct ldlm_lock **,
  95                                  int);
  96
  97        /* Initialize LVB of ldlm resource associated with quota objects */
  98        int (*qmth_lvbo_init)(struct lu_device *, struct ldlm_resource *);
  99
 100        /* Update LVB of ldlm resource associated with quota objects */
 101        int (*qmth_lvbo_update)(struct lu_device *, struct ldlm_resource *,
 102                                struct ptlrpc_request *, int);
 103
 104        /* Return size of LVB to be packed in ldlm message */
 105        int (*qmth_lvbo_size)(struct lu_device *, struct ldlm_lock *);
 106
 107        /* Fill request buffer with lvb */
 108        int (*qmth_lvbo_fill)(struct lu_device *, struct ldlm_lock *, void *,
 109                              int);
 110
 111        /* Free lvb associated with ldlm resource */
 112        int (*qmth_lvbo_free)(struct lu_device *, struct ldlm_resource *);
 113};
 114
 115/* actual handlers are defined in lustre/quota/qmt_handler.c */
 116extern struct qmt_handlers qmt_hdls;
 117
 118/*
 119 * Quota enforcement support on slaves
 120 */
 121
 122struct qsd_instance;
 123
 124/* The quota slave feature is implemented under the form of a library.
 125 * The API is the following:
 126 *
 127 * - qsd_init(): the user (mostly the OSD layer) should first allocate a qsd
 128 *             instance via qsd_init(). This creates all required structures
 129 *             to manage quota enforcement for this target and performs all
 130 *             low-level initialization which does not involve any lustre
 131 *             object. qsd_init() should typically be called when the OSD
 132 *             is being set up.
 133 *
 134 * - qsd_prepare(): This sets up on-disk objects associated with the quota slave
 135 *                feature and initiates the quota reintegration procedure if
 136 *                needed. qsd_prepare() should typically be called when
 137 *                ->ldo_prepare is invoked.
 138 *
 139 * - qsd_start(): a qsd instance should be started once recovery is completed
 140 *              (i.e. when ->ldo_recovery_complete is called). This is used
 141 *              to notify the qsd layer that quota should now be enforced
 142 *              again via the qsd_op_begin/end functions. The last step of the
 143 *              reintegration prodecure (namely usage reconciliation) will be
 144 *              completed during start.
 145 *
 146 * - qsd_fini(): is used to release a qsd_instance structure allocated with
 147 *             qsd_init(). This releases all quota slave objects and frees the
 148 *             structures associated with the qsd_instance.
 149 *
 150 * - qsd_op_begin(): is used to enforce quota, it must be called in the
 151 *                 declaration of each operation. qsd_op_end() should then be
 152 *                 invoked later once all operations have been completed in
 153 *                 order to release/adjust the quota space.
 154 *                 Running qsd_op_begin() before qsd_start() isn't fatal and
 155 *                 will return success.
 156 *                 Once qsd_start() has been run, qsd_op_begin() will block
 157 *                 until the reintegration procedure is completed.
 158 *
 159 * - qsd_op_end(): performs the post operation quota processing. This must be
 160 *               called after the operation transaction stopped.
 161 *               While qsd_op_begin() must be invoked each time a new
 162 *               operation is declared, qsd_op_end() should be called only
 163 *               once for the whole transaction.
 164 *
 165 * - qsd_op_adjust(): triggers pre-acquire/release if necessary.
 166 *
 167 * Below are the function prototypes to be used by OSD layer to manage quota
 168 * enforcement. Arguments are documented where each function is defined.  */
 169
 170struct qsd_instance *qsd_init(const struct lu_env *, char *, struct dt_device *,
 171                              proc_dir_entry_t *);
 172int qsd_prepare(const struct lu_env *, struct qsd_instance *);
 173int qsd_start(const struct lu_env *, struct qsd_instance *);
 174void qsd_fini(const struct lu_env *, struct qsd_instance *);
 175int qsd_op_begin(const struct lu_env *, struct qsd_instance *,
 176                 struct lquota_trans *, struct lquota_id_info *, int *);
 177void qsd_op_end(const struct lu_env *, struct qsd_instance *,
 178                struct lquota_trans *);
 179void qsd_op_adjust(const struct lu_env *, struct qsd_instance *,
 180                   union lquota_id *, int);
 181/* This is exported for the ldiskfs quota migration only,
 182 * see convert_quota_file() */
 183int lquota_disk_write_glb(const struct lu_env *, struct dt_object *,
 184                          __u64, struct lquota_glb_rec *);
 185
 186/*
 187 * Quota information attached to a transaction
 188 */
 189
 190struct lquota_entry;
 191
 192struct lquota_id_info {
 193        /* quota identifier */
 194        union lquota_id          lqi_id;
 195
 196        /* USRQUOTA or GRPQUOTA for now, could be expanded for
 197         * directory quota or other types later.  */
 198        int                      lqi_type;
 199
 200        /* inodes or kbytes to be consumed or released, it could
 201         * be negative when releasing space.  */
 202        long long                lqi_space;
 203
 204        /* quota slave entry structure associated with this ID */
 205        struct lquota_entry     *lqi_qentry;
 206
 207        /* whether we are reporting blocks or inodes */
 208        bool                     lqi_is_blk;
 209};
 210
 211/* Since we enforce only inode quota in meta pool (MDTs), and block quota in
 212 * data pool (OSTs), there are at most 4 quota ids being enforced in a single
 213 * transaction, which is chown transaction:
 214 * original uid and gid, new uid and gid.
 215 *
 216 * This value might need to be revised when directory quota is added.  */
 217#define QUOTA_MAX_TRANSIDS    4
 218
 219/* all qids involved in a single transaction */
 220struct lquota_trans {
 221        unsigned short          lqt_id_cnt;
 222        struct lquota_id_info   lqt_ids[QUOTA_MAX_TRANSIDS];
 223};
 224
 225/* flags for quota local enforcement */
 226#define QUOTA_FL_OVER_USRQUOTA  0x01
 227#define QUOTA_FL_OVER_GRPQUOTA  0x02
 228#define QUOTA_FL_SYNC      0x04
 229
 230#define IS_LQUOTA_RES(res)                                              \
 231        (res->lr_name.name[LUSTRE_RES_ID_SEQ_OFF] == FID_SEQ_QUOTA ||   \
 232         res->lr_name.name[LUSTRE_RES_ID_SEQ_OFF] == FID_SEQ_QUOTA_GLB)
 233
 234/* helper function used by MDT & OFD to retrieve quota accounting information
 235 * on slave */
 236int lquotactl_slv(const struct lu_env *, struct dt_device *,
 237                  struct obd_quotactl *);
 238/** @} quota */
 239#endif /* _LUSTRE_QUOTA_H */
 240