lustre-src/lustre/lov/lov_cl_internal.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 /*
00037  * This file is part of Lustre, http://www.lustre.org/
00038  * Lustre is a trademark of Sun Microsystems, Inc.
00039  *
00040  * Internal interfaces of LOV layer.
00041  *
00042  *   Author: Nikita Danilov <nikita.danilov@sun.com>
00043  */
00044 
00045 #ifndef LOV_CL_INTERNAL_H
00046 #define LOV_CL_INTERNAL_H
00047 
00048 #ifdef __KERNEL__
00049 # include <libcfs/libcfs.h>
00050 #else
00051 # include <liblustre.h>
00052 #endif
00053 
00054 #include <obd.h>
00055 #include <cl_object.h>
00056 #include "lov_internal.h"
00057 
00103 struct lovsub_device;
00104 struct lovsub_object;
00105 struct lovsub_lock;
00106 
00107 enum lov_device_flags {
00108         LOV_DEV_INITIALIZED = 1 << 0
00109 };
00110 
00111 /*
00112  * Upper half.
00113  */
00114 
00121 struct lov_device_emerg {
00125         struct cl_page_list emrg_page_list;
00130         struct cl_io        emrg_subio;
00135         struct lu_env      *emrg_env;
00141         int                 emrg_refcheck;
00142 };
00143 
00144 struct lov_device {
00145         /*
00146          * XXX Locking of lov-private data is missing.
00147          */
00148         struct cl_device          ld_cl;
00149         struct lov_obd           *ld_lov;
00151         __u32                     ld_target_nr;
00152         struct lovsub_device    **ld_target;
00153         __u32                     ld_flags;
00154 
00156         struct lov_device_emerg **ld_emrg;
00161         cfs_mutex_t               ld_mutex;
00162 };
00163 
00167 enum lov_layout_type {
00169         LLT_EMPTY,
00171         LLT_RAID0,
00172         LLT_NR
00173 };
00174 
00189 struct lov_object {
00190         struct cl_object       lo_cl;
00199         cfs_rw_semaphore_t     lo_type_guard;
00203         enum lov_layout_type   lo_type;
00204 
00205         union lov_layout_state {
00206                 struct lov_layout_raid0 {
00207                         unsigned               lo_nr;
00208                         struct lov_stripe_md  *lo_lsm;
00224                         struct lovsub_object **lo_sub;
00231                         int                    lo_attr_valid;
00236                         struct cl_attr         lo_attr;
00237                 } raid0;
00238                 struct lov_layout_state_empty {
00239                 } empty;
00240         } u;
00245         cfs_task_t            *lo_owner;
00246 };
00247 
00251 enum lov_sub_flags {
00253         LSF_HELD = 1 << 0
00254 };
00255 
00259 struct lov_lock_sub {
00261         struct lovsub_lock  *sub_lock;
00263         unsigned             sub_flags;
00264         int                  sub_stripe;
00265         struct cl_lock_descr sub_descr;
00266         struct cl_lock_descr sub_got;
00267 };
00268 
00272 struct lov_lock {
00273         struct cl_lock_slice   lls_cl;
00275         int                    lls_nr;
00279         unsigned               lls_nr_filled;
00284         int                    lls_cancel_race:1;
00324         struct lov_lock_sub   *lls_sub;
00328         struct cl_lock_descr   lls_orig;
00329 };
00330 
00331 struct lov_page {
00332         struct cl_page_slice lps_cl;
00333         int                  lps_invalid;
00334 };
00335 
00336 /*
00337  * Bottom half.
00338  */
00339 
00340 struct lovsub_device {
00341         struct cl_device   acid_cl;
00342         struct lov_device *acid_super;
00343         int                acid_idx;
00344         struct cl_device  *acid_next;
00345 };
00346 
00347 struct lovsub_object {
00348         struct cl_object_header lso_header;
00349         struct cl_object        lso_cl;
00350         struct lov_object      *lso_super;
00351         int                     lso_index;
00352 };
00353 
00361 struct lov_lock_link {
00362         struct lov_lock *lll_super;
00364         int              lll_idx;
00369         cfs_list_t       lll_list;
00370 };
00371 
00375 struct lovsub_lock {
00376         struct cl_lock_slice  lss_cl;
00381         cfs_list_t            lss_parents;
00390         struct cl_lock       *lss_active;
00391 };
00392 
00396 struct lov_sublock_env {
00397         const struct lu_env *lse_env;
00398         struct cl_io        *lse_io;
00399         struct lov_io_sub   *lse_sub;
00400 };
00401 
00402 struct lovsub_page {
00403         struct cl_page_slice lsb_cl;
00404 };
00405 
00406 
00407 struct lov_thread_info {
00408         struct cl_object_conf   lti_stripe_conf;
00409         struct lu_fid           lti_fid;
00410         struct cl_lock_descr    lti_ldescr;
00411         struct ost_lvb          lti_lvb;
00412         struct cl_2queue        lti_cl2q;
00413         union  lov_layout_state lti_state;
00414         struct cl_lock_closure  lti_closure;
00415         cfs_waitlink_t          lti_waiter;
00416 };
00417 
00421 struct lov_io_sub {
00422         int                  sub_stripe;
00428         struct cl_io        *sub_io;
00433         cfs_list_t           sub_linkage;
00438         int                  sub_io_initialized;
00443         int                  sub_borrowed;
00447         struct lu_env *sub_env;
00453         int                  sub_refcheck;
00454         int                  sub_refcheck2;
00455         int                  sub_reenter;
00456         void                *sub_cookie;
00457 };
00458 
00462 struct lov_io {
00464         struct cl_io_slice lis_cl;
00469         struct lov_object *lis_object;
00478         loff_t             lis_io_endpos;
00479 
00484         obd_off            lis_pos;
00489         obd_off            lis_endpos;
00490 
00491         int                lis_mem_frozen;
00492         int                lis_stripe_count;
00493         int                lis_active_subios;
00494 
00498         int                lis_single_subio_index;
00499         struct cl_io       lis_single_subio;
00500 
00504         int                lis_nr_subios;
00505         struct lov_io_sub *lis_subs;
00509         cfs_list_t         lis_active;
00510 };
00511 
00512 struct lov_session {
00513         struct lov_io          ls_io;
00514         struct lov_sublock_env ls_subenv;
00515 };
00516 
00520 struct lov_req {
00521         struct cl_req_slice lr_cl;
00522 };
00523 
00527 struct lovsub_req {
00528         struct cl_req_slice lsrq_cl;
00529 };
00530 
00531 extern struct lu_device_type lov_device_type;
00532 extern struct lu_device_type lovsub_device_type;
00533 
00534 extern struct lu_context_key lov_key;
00535 extern struct lu_context_key lov_session_key;
00536 
00537 extern cfs_mem_cache_t *lov_page_kmem;
00538 extern cfs_mem_cache_t *lov_lock_kmem;
00539 extern cfs_mem_cache_t *lov_object_kmem;
00540 extern cfs_mem_cache_t *lov_thread_kmem;
00541 extern cfs_mem_cache_t *lov_session_kmem;
00542 extern cfs_mem_cache_t *lov_req_kmem;
00543 
00544 extern cfs_mem_cache_t *lovsub_page_kmem;
00545 extern cfs_mem_cache_t *lovsub_lock_kmem;
00546 extern cfs_mem_cache_t *lovsub_object_kmem;
00547 extern cfs_mem_cache_t *lovsub_req_kmem;
00548 
00549 extern cfs_mem_cache_t *lov_lock_link_kmem;
00550 
00551 int   lov_object_init     (const struct lu_env *env, struct lu_object *obj,
00552                            const struct lu_object_conf *conf);
00553 int   lovsub_object_init  (const struct lu_env *env, struct lu_object *obj,
00554                            const struct lu_object_conf *conf);
00555 int   lov_lock_init       (const struct lu_env *env, struct cl_object *obj,
00556                            struct cl_lock *lock, const struct cl_io *io);
00557 int   lov_io_init         (const struct lu_env *env, struct cl_object *obj,
00558                            struct cl_io *io);
00559 int   lovsub_lock_init    (const struct lu_env *env, struct cl_object *obj,
00560                            struct cl_lock *lock, const struct cl_io *io);
00561 
00562 int   lov_lock_init_raid0 (const struct lu_env *env, struct cl_object *obj,
00563                            struct cl_lock *lock, const struct cl_io *io);
00564 int   lov_io_init_raid0   (const struct lu_env *env, struct cl_object *obj,
00565                            struct cl_io *io);
00566 int   lov_io_init_empty   (const struct lu_env *env, struct cl_object *obj,
00567                            struct cl_io *io);
00568 void  lov_lock_unlink     (const struct lu_env *env, struct lov_lock_link *link,
00569                            struct lovsub_lock *sub);
00570 
00571 struct lov_io_sub *lov_sub_get(const struct lu_env *env, struct lov_io *lio,
00572                                int stripe);
00573 void  lov_sub_put             (struct lov_io_sub *sub);
00574 int   lov_sublock_modify  (const struct lu_env *env, struct lov_lock *lov,
00575                            struct lovsub_lock *sublock,
00576                            const struct cl_lock_descr *d, int idx);
00577 
00578 
00579 struct cl_page *lov_page_init   (const struct lu_env *env, struct cl_object *ob,
00580                                  struct cl_page *page, cfs_page_t *vmpage);
00581 struct cl_page *lovsub_page_init(const struct lu_env *env, struct cl_object *ob,
00582                                  struct cl_page *page, cfs_page_t *vmpage);
00583 
00584 struct cl_page   *lov_page_init_empty(const struct lu_env *env,
00585                                       struct cl_object *obj,
00586                                       struct cl_page *page, cfs_page_t *vmpage);
00587 struct cl_page   *lov_page_init_raid0(const struct lu_env *env,
00588                                       struct cl_object *obj,
00589                                       struct cl_page *page, cfs_page_t *vmpage);
00590 struct lu_object *lov_object_alloc   (const struct lu_env *env,
00591                                       const struct lu_object_header *hdr,
00592                                       struct lu_device *dev);
00593 struct lu_object *lovsub_object_alloc(const struct lu_env *env,
00594                                       const struct lu_object_header *hdr,
00595                                       struct lu_device *dev);
00596 
00597 struct lov_lock_link *lov_lock_link_find(const struct lu_env *env,
00598                                          struct lov_lock *lck,
00599                                          struct lovsub_lock *sub);
00600 struct lov_io_sub    *lov_page_subio    (const struct lu_env *env,
00601                                          struct lov_io *lio,
00602                                          const struct cl_page_slice *slice);
00603 
00604 
00605 #define lov_foreach_target(lov, var)                    \
00606         for (var = 0; var < lov_targets_nr(lov); ++var)
00607 
00608 /*****************************************************************************
00609  *
00610  * Type conversions.
00611  *
00612  * Accessors.
00613  *
00614  */
00615 
00616 static inline struct lov_session *lov_env_session(const struct lu_env *env)
00617 {
00618         struct lov_session *ses;
00619 
00620         ses = lu_context_key_get(env->le_ses, &lov_session_key);
00621         LASSERT(ses != NULL);
00622         return ses;
00623 }
00624 
00625 static inline struct lov_io *lov_env_io(const struct lu_env *env)
00626 {
00627         return &lov_env_session(env)->ls_io;
00628 }
00629 
00630 static inline int lov_is_object(const struct lu_object *obj)
00631 {
00632         return obj->lo_dev->ld_type == &lov_device_type;
00633 }
00634 
00635 static inline int lovsub_is_object(const struct lu_object *obj)
00636 {
00637         return obj->lo_dev->ld_type == &lovsub_device_type;
00638 }
00639 
00640 static inline struct lu_device *lov2lu_dev(struct lov_device *lov)
00641 {
00642         return &lov->ld_cl.cd_lu_dev;
00643 }
00644 
00645 static inline struct lov_device *lu2lov_dev(const struct lu_device *d)
00646 {
00647         LINVRNT(d->ld_type == &lov_device_type);
00648         return container_of0(d, struct lov_device, ld_cl.cd_lu_dev);
00649 }
00650 
00651 static inline struct cl_device *lovsub2cl_dev(struct lovsub_device *lovsub)
00652 {
00653         return &lovsub->acid_cl;
00654 }
00655 
00656 static inline struct lu_device *lovsub2lu_dev(struct lovsub_device *lovsub)
00657 {
00658         return &lovsub2cl_dev(lovsub)->cd_lu_dev;
00659 }
00660 
00661 static inline struct lovsub_device *lu2lovsub_dev(const struct lu_device *d)
00662 {
00663         LINVRNT(d->ld_type == &lovsub_device_type);
00664         return container_of0(d, struct lovsub_device, acid_cl.cd_lu_dev);
00665 }
00666 
00667 static inline struct lovsub_device *cl2lovsub_dev(const struct cl_device *d)
00668 {
00669         LINVRNT(d->cd_lu_dev.ld_type == &lovsub_device_type);
00670         return container_of0(d, struct lovsub_device, acid_cl);
00671 }
00672 
00673 static inline struct lu_object *lov2lu(struct lov_object *lov)
00674 {
00675         return &lov->lo_cl.co_lu;
00676 }
00677 
00678 static inline struct cl_object *lov2cl(struct lov_object *lov)
00679 {
00680         return &lov->lo_cl;
00681 }
00682 
00683 static inline struct lov_object *lu2lov(const struct lu_object *obj)
00684 {
00685         LINVRNT(lov_is_object(obj));
00686         return container_of0(obj, struct lov_object, lo_cl.co_lu);
00687 }
00688 
00689 static inline struct lov_object *cl2lov(const struct cl_object *obj)
00690 {
00691         LINVRNT(lov_is_object(&obj->co_lu));
00692         return container_of0(obj, struct lov_object, lo_cl);
00693 }
00694 
00695 static inline struct lu_object *lovsub2lu(struct lovsub_object *los)
00696 {
00697         return &los->lso_cl.co_lu;
00698 }
00699 
00700 static inline struct cl_object *lovsub2cl(struct lovsub_object *los)
00701 {
00702         return &los->lso_cl;
00703 }
00704 
00705 static inline struct lovsub_object *cl2lovsub(const struct cl_object *obj)
00706 {
00707         LINVRNT(lovsub_is_object(&obj->co_lu));
00708         return container_of0(obj, struct lovsub_object, lso_cl);
00709 }
00710 
00711 static inline struct lovsub_object *lu2lovsub(const struct lu_object *obj)
00712 {
00713         LINVRNT(lovsub_is_object(obj));
00714         return container_of0(obj, struct lovsub_object, lso_cl.co_lu);
00715 }
00716 
00717 static inline struct lovsub_lock *
00718 cl2lovsub_lock(const struct cl_lock_slice *slice)
00719 {
00720         LINVRNT(lovsub_is_object(&slice->cls_obj->co_lu));
00721         return container_of(slice, struct lovsub_lock, lss_cl);
00722 }
00723 
00724 static inline struct lovsub_lock *cl2sub_lock(const struct cl_lock *lock)
00725 {
00726         const struct cl_lock_slice *slice;
00727 
00728         slice = cl_lock_at(lock, &lovsub_device_type);
00729         LASSERT(slice != NULL);
00730         return cl2lovsub_lock(slice);
00731 }
00732 
00733 static inline struct lov_lock *cl2lov_lock(const struct cl_lock_slice *slice)
00734 {
00735         LINVRNT(lov_is_object(&slice->cls_obj->co_lu));
00736         return container_of(slice, struct lov_lock, lls_cl);
00737 }
00738 
00739 static inline struct lov_page *cl2lov_page(const struct cl_page_slice *slice)
00740 {
00741         LINVRNT(lov_is_object(&slice->cpl_obj->co_lu));
00742         return container_of0(slice, struct lov_page, lps_cl);
00743 }
00744 
00745 static inline struct lov_req *cl2lov_req(const struct cl_req_slice *slice)
00746 {
00747         return container_of0(slice, struct lov_req, lr_cl);
00748 }
00749 
00750 static inline struct lovsub_page *
00751 cl2lovsub_page(const struct cl_page_slice *slice)
00752 {
00753         LINVRNT(lovsub_is_object(&slice->cpl_obj->co_lu));
00754         return container_of0(slice, struct lovsub_page, lsb_cl);
00755 }
00756 
00757 static inline struct lovsub_req *cl2lovsub_req(const struct cl_req_slice *slice)
00758 {
00759         return container_of0(slice, struct lovsub_req, lsrq_cl);
00760 }
00761 
00762 static inline struct cl_page *lov_sub_page(const struct cl_page_slice *slice)
00763 {
00764         return slice->cpl_page->cp_child;
00765 }
00766 
00767 static inline struct lov_io *cl2lov_io(const struct lu_env *env,
00768                                 const struct cl_io_slice *ios)
00769 {
00770         struct lov_io *lio;
00771 
00772         lio = container_of(ios, struct lov_io, lis_cl);
00773         LASSERT(lio == lov_env_io(env));
00774         return lio;
00775 }
00776 
00777 static inline int lov_targets_nr(const struct lov_device *lov)
00778 {
00779         return lov->ld_lov->desc.ld_tgt_count;
00780 }
00781 
00782 static inline struct lov_thread_info *lov_env_info(const struct lu_env *env)
00783 {
00784         struct lov_thread_info *info;
00785 
00786         info = lu_context_key_get(&env->le_ctx, &lov_key);
00787         LASSERT(info != NULL);
00788         return info;
00789 }
00790 
00791 static inline struct lov_layout_raid0 *lov_r0(struct lov_object *lov)
00792 {
00793         struct lov_layout_raid0 *raid0;
00794 
00795         LASSERT(lov->lo_type == LLT_RAID0);
00796         raid0 = &lov->u.raid0;
00797         LASSERT(raid0->lo_lsm->lsm_wire.lw_magic == LOV_MAGIC ||
00798                 raid0->lo_lsm->lsm_wire.lw_magic == LOV_MAGIC_V3);
00799         return raid0;
00800 }
00801 
00804 #endif
00805 

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.