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, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * Implementation of cl_object for LOVSUB layer.
36 * Author: Nikita Danilov <nikita.danilov@sun.com>
39 #define DEBUG_SUBSYSTEM S_LOV
41 #include "lov_cl_internal.h"
47 /*****************************************************************************
49 * Lovsub object operations.
53 int lovsub_object_init(const struct lu_env *env, struct lu_object *obj,
54 const struct lu_object_conf *conf)
56 struct lovsub_device *dev = lu2lovsub_dev(obj->lo_dev);
57 struct lu_object *below;
58 struct lu_device *under;
63 under = &dev->acid_next->cd_lu_dev;
64 below = under->ld_ops->ldo_object_alloc(env, obj->lo_header, under);
66 lu_object_add(obj, below);
74 static void lovsub_object_free(const struct lu_env *env, struct lu_object *obj)
76 struct lovsub_object *los = lu2lovsub(obj);
77 struct lov_object *lov = los->lso_super;
80 /* We can't assume lov was assigned here, because of the shadow
81 * object handling in lu_object_find.
84 LASSERT(lov->lo_type == LLT_RAID0);
85 LASSERT(lov->u.raid0.lo_sub[los->lso_index] == los);
86 spin_lock(&lov->u.raid0.lo_sub_lock);
87 lov->u.raid0.lo_sub[los->lso_index] = NULL;
88 spin_unlock(&lov->u.raid0.lo_sub_lock);
92 lu_object_header_fini(&los->lso_header.coh_lu);
93 OBD_SLAB_FREE_PTR(los, lovsub_object_kmem);
97 static int lovsub_object_print(const struct lu_env *env, void *cookie,
98 lu_printer_t p, const struct lu_object *obj)
100 struct lovsub_object *los = lu2lovsub(obj);
102 return (*p)(env, cookie, "[%d]", los->lso_index);
105 static int lovsub_attr_set(const struct lu_env *env, struct cl_object *obj,
106 const struct cl_attr *attr, unsigned valid)
108 struct lov_object *lov = cl2lovsub(obj)->lso_super;
111 lov_r0(lov)->lo_attr_valid = 0;
115 static int lovsub_object_glimpse(const struct lu_env *env,
116 const struct cl_object *obj,
119 struct lovsub_object *los = cl2lovsub(obj);
122 RETURN(cl_object_glimpse(env, &los->lso_super->lo_cl, lvb));
127 static const struct cl_object_operations lovsub_ops = {
128 .coo_page_init = lovsub_page_init,
129 .coo_lock_init = lovsub_lock_init,
130 .coo_attr_set = lovsub_attr_set,
131 .coo_glimpse = lovsub_object_glimpse
134 static const struct lu_object_operations lovsub_lu_obj_ops = {
135 .loo_object_init = lovsub_object_init,
136 .loo_object_delete = NULL,
137 .loo_object_release = NULL,
138 .loo_object_free = lovsub_object_free,
139 .loo_object_print = lovsub_object_print,
140 .loo_object_invariant = NULL
143 struct lu_object *lovsub_object_alloc(const struct lu_env *env,
144 const struct lu_object_header *unused,
145 struct lu_device *dev)
147 struct lovsub_object *los;
148 struct lu_object *obj;
151 OBD_SLAB_ALLOC_PTR_GFP(los, lovsub_object_kmem, CFS_ALLOC_IO);
153 struct cl_object_header *hdr;
155 obj = lovsub2lu(los);
156 hdr = &los->lso_header;
157 cl_object_header_init(hdr);
158 lu_object_init(obj, &hdr->coh_lu, dev);
159 lu_object_add_top(&hdr->coh_lu, obj);
160 los->lso_cl.co_ops = &lovsub_ops;
161 obj->lo_ops = &lovsub_lu_obj_ops;