lustre-src/lustre/include/lustre_fid.h

00001 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * GPL HEADER START
00005  *
00006  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License version 2 only,
00010  * as published by the Free Software Foundation.
00011  *
00012  * This program is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * General Public License version 2 for more details (a copy is included
00016  * in the LICENSE file that accompanied this code).
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * version 2 along with this program; If not, see
00020  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
00021  *
00022  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
00023  * CA 95054 USA or visit www.sun.com if you need additional information or
00024  * have any questions.
00025  *
00026  * GPL HEADER END
00027  */
00028 /*
00029  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
00030  * Use is subject to license terms.
00031  */
00032 /*
00033  * This file is part of Lustre, http://www.lustre.org/
00034  * Lustre is a trademark of Sun Microsystems, Inc.
00035  *
00036  * lustre/include/lustre_fid.h
00037  *
00038  * Author: Yury Umanets <umka@clusterfs.com>
00039  */
00040 
00041 #ifndef __LINUX_FID_H
00042 #define __LINUX_FID_H
00043 
00049 /*
00050  * struct lu_fid
00051  */
00052 #include <lustre/lustre_idl.h>
00053 #include <lustre_req_layout.h>
00054 #include <lustre_mdt.h>
00055 
00056 #include <libcfs/libcfs.h>
00057 
00058 struct lu_site;
00059 struct lu_context;
00060 
00061 /* Whole sequences space range and zero range definitions */
00062 extern const struct lu_seq_range LUSTRE_SEQ_SPACE_RANGE;
00063 extern const struct lu_seq_range LUSTRE_SEQ_ZERO_RANGE;
00064 extern const struct lu_fid LUSTRE_BFL_FID;
00065 extern const struct lu_fid LU_OBF_FID;
00066 extern const struct lu_fid LU_DOT_LUSTRE_FID;
00067 
00068 enum {
00069         /*
00070          * This is how may FIDs may be allocated in one sequence. 16384 for
00071          * now.
00072          */
00073         LUSTRE_SEQ_MAX_WIDTH = 0x0000000000000400ULL,
00074 
00075         /*
00076          * How many sequences may be allocate for meta-sequence (this is 128
00077          * sequences).
00078          */
00079         /* changed to 16 to avoid overflow in test11 */
00080         LUSTRE_SEQ_META_WIDTH = 0x0000000000000010ULL,
00081 
00082         /*
00083          * This is how many sequences may be in one super-sequence allocated to
00084          * MDTs.
00085          */
00086         LUSTRE_SEQ_SUPER_WIDTH = ((1<< 30) * LUSTRE_SEQ_META_WIDTH)
00087 };
00088 
00090 #define FID_SEQ_LOCAL_FILE      (FID_SEQ_START + 1)
00091 
00093 #define LU_DOT_LUSTRE_SEQ       (FID_SEQ_START + 0x02ULL)
00094 
00095 /* Note that reserved SEQ numbers below 12 will conflict with ldiskfs
00096  * inodes in the IGIF namespace, so these reserved SEQ numbers must be
00097  * used sparingly until ldiskfs-based MDT backends and/or IGIF FIDs 
00098  * have been completely removed. */
00099 
00101 #define FID_SEQ_DISTRIBUTED_START     (FID_SEQ_START + 0x400ULL)
00102 
00104 enum {
00106         OSD_OI_FID_16_OID       = 2UL,
00108         FLD_INDEX_OID           = 3UL,
00110         FID_SEQ_CTL_OID         = 4UL,
00111         FID_SEQ_SRV_OID         = 5UL,
00113         MDD_ROOT_INDEX_OID      = 6UL,
00114         MDD_ORPHAN_OID          = 7UL,
00115         MDD_LOV_OBJ_OID         = 8UL,
00116         MDD_CAPA_KEYS_OID       = 9UL,
00117         MDD_OBJECTS_OID         = 10UL,
00119         MDT_LAST_RECV_OID       = 11UL,
00121         OSD_REM_OBJ_DIR_OID     = 12UL,
00122 };
00123 
00124 static inline void lu_local_obj_fid(struct lu_fid *fid, __u32 oid)
00125 {
00126         fid->f_seq = FID_SEQ_LOCAL_FILE;
00127         fid->f_oid = oid;
00128         fid->f_ver = 0;
00129 }
00130 
00131 enum lu_mgr_type {
00132         LUSTRE_SEQ_SERVER,
00133         LUSTRE_SEQ_CONTROLLER
00134 };
00135 
00136 enum lu_cli_type {
00137         LUSTRE_SEQ_METADATA,
00138         LUSTRE_SEQ_DATA
00139 };
00140 
00141 struct lu_server_seq;
00142 
00143 /* Client sequence manager interface. */
00144 struct lu_client_seq {
00145         /* Sequence-controller export. */
00146         struct obd_export      *lcs_exp;
00147         cfs_semaphore_t         lcs_sem;
00148 
00149         /*
00150          * Range of allowed for allocation sequeces. When using lu_client_seq on
00151          * clients, this contains meta-sequence range. And for servers this
00152          * contains super-sequence range.
00153          */
00154         struct lu_seq_range         lcs_space;
00155 
00156         /* Seq related proc */
00157         cfs_proc_dir_entry_t   *lcs_proc_dir;
00158 
00159         /* This holds last allocated fid in last obtained seq */
00160         struct lu_fid           lcs_fid;
00161 
00162         /* LUSTRE_SEQ_METADATA or LUSTRE_SEQ_DATA */
00163         enum lu_cli_type        lcs_type;
00164 
00165         /*
00166          * Service uuid, passed from MDT + seq name to form unique seq name to
00167          * use it with procfs.
00168          */
00169         char                    lcs_name[80];
00170 
00171         /*
00172          * Sequence width, that is how many objects may be allocated in one
00173          * sequence. Default value for it is LUSTRE_SEQ_MAX_WIDTH.
00174          */
00175         __u64                   lcs_width;
00176 
00177         /* Seq-server for direct talking */
00178         struct lu_server_seq   *lcs_srv;
00179 };
00180 
00181 /* server sequence manager interface */
00182 struct lu_server_seq {
00183         /* Available sequences space */
00184         struct lu_seq_range         lss_space;
00185 
00186         /*
00187          * Device for server side seq manager needs (saving sequences to backing
00188          * store).
00189          */
00190         struct dt_device       *lss_dev;
00191 
00192         /* /seq file object device */
00193         struct dt_object       *lss_obj;
00194 
00195         /* Seq related proc */
00196         cfs_proc_dir_entry_t   *lss_proc_dir;
00197 
00198         /* LUSTRE_SEQ_SERVER or LUSTRE_SEQ_CONTROLLER */
00199         enum lu_mgr_type       lss_type;
00200 
00201         /* Client interafce to request controller */
00202         struct lu_client_seq   *lss_cli;
00203 
00204         /* Semaphore for protecting allocation */
00205         cfs_semaphore_t         lss_sem;
00206 
00207         /*
00208          * Service uuid, passed from MDT + seq name to form unique seq name to
00209          * use it with procfs.
00210          */
00211         char                    lss_name[80];
00212 
00213         /*
00214          * Allocation chunks for super and meta sequences. Default values are
00215          * LUSTRE_SEQ_SUPER_WIDTH and LUSTRE_SEQ_META_WIDTH.
00216          */
00217         __u64                   lss_width;
00218 
00222         struct md_site         *lss_site;
00223 };
00224 
00225 int seq_query(struct com_thread_info *info);
00226 
00227 /* Server methods */
00228 int seq_server_init(struct lu_server_seq *seq,
00229                     struct dt_device *dev,
00230                     const char *prefix,
00231                     enum lu_mgr_type type,
00232                     struct md_site *ls,
00233                     const struct lu_env *env);
00234 
00235 void seq_server_fini(struct lu_server_seq *seq,
00236                      const struct lu_env *env);
00237 
00238 int seq_server_alloc_super(struct lu_server_seq *seq,
00239                            struct lu_seq_range *in,
00240                            struct lu_seq_range *out,
00241                            const struct lu_env *env);
00242 
00243 int seq_server_alloc_meta(struct lu_server_seq *seq,
00244                           struct lu_seq_range *in,
00245                           struct lu_seq_range *out,
00246                           const struct lu_env *env);
00247 
00248 int seq_server_set_cli(struct lu_server_seq *seq,
00249                        struct lu_client_seq *cli,
00250                        const struct lu_env *env);
00251 
00252 /* Client methods */
00253 int seq_client_init(struct lu_client_seq *seq,
00254                     struct obd_export *exp,
00255                     enum lu_cli_type type,
00256                     const char *prefix,
00257                     struct lu_server_seq *srv);
00258 
00259 void seq_client_fini(struct lu_client_seq *seq);
00260 
00261 void seq_client_flush(struct lu_client_seq *seq);
00262 
00263 int seq_client_alloc_fid(struct lu_client_seq *seq,
00264                          struct lu_fid *fid);
00265 
00266 /* Fids common stuff */
00267 int fid_is_local(const struct lu_env *env,
00268                  struct lu_site *site, const struct lu_fid *fid);
00269 
00270 /* fid locking */
00271 
00272 struct ldlm_namespace;
00273 
00274 enum {
00275         LUSTRE_RES_ID_SEQ_OFF = 0,
00276         LUSTRE_RES_ID_OID_OFF = 1,
00277         LUSTRE_RES_ID_VER_OFF = 2,
00278         LUSTRE_RES_ID_HSH_OFF = 3
00279 };
00280 
00281 /*
00282  * Build (DLM) resource name from fid.
00283  */
00284 static inline struct ldlm_res_id *
00285 fid_build_reg_res_name(const struct lu_fid *f,
00286                        struct ldlm_res_id *name)
00287 {
00288         memset(name, 0, sizeof *name);
00289         name->name[LUSTRE_RES_ID_SEQ_OFF] = fid_seq(f);
00290         name->name[LUSTRE_RES_ID_OID_OFF] = fid_oid(f);
00291         name->name[LUSTRE_RES_ID_VER_OFF] = fid_ver(f);
00292         return name;
00293 }
00294 
00295 /*
00296  * Return true if resource is for object identified by fid.
00297  */
00298 static inline int fid_res_name_eq(const struct lu_fid *f,
00299                                   const struct ldlm_res_id *name)
00300 {
00301         return
00302                 name->name[LUSTRE_RES_ID_SEQ_OFF] == fid_seq(f) &&
00303                 name->name[LUSTRE_RES_ID_OID_OFF] == fid_oid(f) &&
00304                 name->name[LUSTRE_RES_ID_VER_OFF] == fid_ver(f);
00305 }
00306 
00307 
00308 static inline struct ldlm_res_id *
00309 fid_build_pdo_res_name(const struct lu_fid *f,
00310                        unsigned int hash,
00311                        struct ldlm_res_id *name)
00312 {
00313         fid_build_reg_res_name(f, name);
00314         name->name[LUSTRE_RES_ID_HSH_OFF] = hash;
00315         return name;
00316 }
00317 
00318 static inline __u64 fid_flatten(const struct lu_fid *fid)
00319 {
00320         return (fid_seq(fid) - 1) * LUSTRE_SEQ_MAX_WIDTH + fid_oid(fid);
00321 }
00322 
00323 #define LUSTRE_SEQ_SRV_NAME "seq_srv"
00324 #define LUSTRE_SEQ_CTL_NAME "seq_ctl"
00325 
00326 /* Range common stuff */
00327 static inline void range_cpu_to_le(struct lu_seq_range *dst, const struct lu_seq_range *src)
00328 {
00329         dst->lsr_start = cpu_to_le64(src->lsr_start);
00330         dst->lsr_end = cpu_to_le64(src->lsr_end);
00331         dst->lsr_mdt = cpu_to_le32(src->lsr_mdt);
00332 }
00333 
00334 static inline void range_le_to_cpu(struct lu_seq_range *dst, const struct lu_seq_range *src)
00335 {
00336         dst->lsr_start = le64_to_cpu(src->lsr_start);
00337         dst->lsr_end = le64_to_cpu(src->lsr_end);
00338         dst->lsr_mdt = le32_to_cpu(src->lsr_mdt);
00339 }
00340 
00341 static inline void range_cpu_to_be(struct lu_seq_range *dst, const struct lu_seq_range *src)
00342 {
00343         dst->lsr_start = cpu_to_be64(src->lsr_start);
00344         dst->lsr_end = cpu_to_be64(src->lsr_end);
00345         dst->lsr_mdt = cpu_to_be32(src->lsr_mdt);
00346 }
00347 
00348 static inline void range_be_to_cpu(struct lu_seq_range *dst, const struct lu_seq_range *src)
00349 {
00350         dst->lsr_start = be64_to_cpu(src->lsr_start);
00351         dst->lsr_end = be64_to_cpu(src->lsr_end);
00352         dst->lsr_mdt = be32_to_cpu(src->lsr_mdt);
00353 }
00354 
00357 #endif /* __LINUX_FID_H */

Generated on Mon Apr 12 04:18:20 2010 for Lustre 1.10.0.40-0-g9a80ff7 by doxygen 1.4.7

Contact | About Sun | News | Employment | Privacy | Terms of Use | Trademarks | (C) 2008 Sun Microsystems, Inc.