Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 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, see |
Oleg Drokin | 6a5b99a | 2016-06-14 23:33:40 -0400 | [diff] [blame] | 18 | * http://www.gnu.org/licenses/gpl-2.0.html |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 19 | * |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 20 | * GPL HEADER END |
| 21 | */ |
| 22 | /* |
| 23 | * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. |
| 24 | * Use is subject to license terms. |
| 25 | * |
Andreas Dilger | 1dc563a | 2015-11-08 18:09:37 -0500 | [diff] [blame] | 26 | * Copyright (c) 2012, 2015 Intel Corporation. |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 27 | */ |
| 28 | /* |
| 29 | * This file is part of Lustre, http://www.lustre.org/ |
| 30 | * Lustre is a trademark of Sun Microsystems, Inc. |
| 31 | * |
| 32 | * Implementation of cl_object for LOVSUB layer. |
| 33 | * |
| 34 | * Author: Nikita Danilov <nikita.danilov@sun.com> |
| 35 | */ |
| 36 | |
| 37 | #define DEBUG_SUBSYSTEM S_LOV |
| 38 | |
| 39 | #include "lov_cl_internal.h" |
| 40 | |
| 41 | /** \addtogroup lov |
| 42 | * @{ |
| 43 | */ |
| 44 | |
| 45 | /***************************************************************************** |
| 46 | * |
| 47 | * Lovsub object operations. |
| 48 | * |
| 49 | */ |
| 50 | |
| 51 | int lovsub_object_init(const struct lu_env *env, struct lu_object *obj, |
| 52 | const struct lu_object_conf *conf) |
| 53 | { |
| 54 | struct lovsub_device *dev = lu2lovsub_dev(obj->lo_dev); |
| 55 | struct lu_object *below; |
| 56 | struct lu_device *under; |
| 57 | |
| 58 | int result; |
| 59 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 60 | under = &dev->acid_next->cd_lu_dev; |
| 61 | below = under->ld_ops->ldo_object_alloc(env, obj->lo_header, under); |
Oleg Drokin | 00697c4 | 2016-02-16 00:46:45 -0500 | [diff] [blame] | 62 | if (below) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 63 | lu_object_add(obj, below); |
| 64 | cl_object_page_init(lu2cl(obj), sizeof(struct lovsub_page)); |
| 65 | result = 0; |
Oleg Drokin | da5ecb4 | 2016-04-01 15:18:01 -0400 | [diff] [blame] | 66 | } else { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 67 | result = -ENOMEM; |
Oleg Drokin | da5ecb4 | 2016-04-01 15:18:01 -0400 | [diff] [blame] | 68 | } |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 69 | return result; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static void lovsub_object_free(const struct lu_env *env, struct lu_object *obj) |
| 73 | { |
| 74 | struct lovsub_object *los = lu2lovsub(obj); |
| 75 | struct lov_object *lov = los->lso_super; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 76 | |
| 77 | /* We can't assume lov was assigned here, because of the shadow |
| 78 | * object handling in lu_object_find. |
| 79 | */ |
| 80 | if (lov) { |
| 81 | LASSERT(lov->lo_type == LLT_RAID0); |
| 82 | LASSERT(lov->u.raid0.lo_sub[los->lso_index] == los); |
| 83 | spin_lock(&lov->u.raid0.lo_sub_lock); |
| 84 | lov->u.raid0.lo_sub[los->lso_index] = NULL; |
| 85 | spin_unlock(&lov->u.raid0.lo_sub_lock); |
| 86 | } |
| 87 | |
| 88 | lu_object_fini(obj); |
| 89 | lu_object_header_fini(&los->lso_header.coh_lu); |
Mike Rapoport | 50d3036 | 2015-10-20 12:39:51 +0300 | [diff] [blame] | 90 | kmem_cache_free(lovsub_object_kmem, los); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static int lovsub_object_print(const struct lu_env *env, void *cookie, |
| 94 | lu_printer_t p, const struct lu_object *obj) |
| 95 | { |
| 96 | struct lovsub_object *los = lu2lovsub(obj); |
| 97 | |
| 98 | return (*p)(env, cookie, "[%d]", los->lso_index); |
| 99 | } |
| 100 | |
| 101 | static int lovsub_attr_set(const struct lu_env *env, struct cl_object *obj, |
| 102 | const struct cl_attr *attr, unsigned valid) |
| 103 | { |
| 104 | struct lov_object *lov = cl2lovsub(obj)->lso_super; |
| 105 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 106 | lov_r0(lov)->lo_attr_valid = 0; |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 107 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | static int lovsub_object_glimpse(const struct lu_env *env, |
| 111 | const struct cl_object *obj, |
| 112 | struct ost_lvb *lvb) |
| 113 | { |
| 114 | struct lovsub_object *los = cl2lovsub(obj); |
| 115 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 116 | return cl_object_glimpse(env, &los->lso_super->lo_cl, lvb); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 117 | } |
| 118 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 119 | static const struct cl_object_operations lovsub_ops = { |
| 120 | .coo_page_init = lovsub_page_init, |
| 121 | .coo_lock_init = lovsub_lock_init, |
| 122 | .coo_attr_set = lovsub_attr_set, |
| 123 | .coo_glimpse = lovsub_object_glimpse |
| 124 | }; |
| 125 | |
| 126 | static const struct lu_object_operations lovsub_lu_obj_ops = { |
| 127 | .loo_object_init = lovsub_object_init, |
| 128 | .loo_object_delete = NULL, |
| 129 | .loo_object_release = NULL, |
| 130 | .loo_object_free = lovsub_object_free, |
| 131 | .loo_object_print = lovsub_object_print, |
| 132 | .loo_object_invariant = NULL |
| 133 | }; |
| 134 | |
| 135 | struct lu_object *lovsub_object_alloc(const struct lu_env *env, |
| 136 | const struct lu_object_header *unused, |
| 137 | struct lu_device *dev) |
| 138 | { |
| 139 | struct lovsub_object *los; |
| 140 | struct lu_object *obj; |
| 141 | |
Amitoj Kaur Chawla | 8210132 | 2016-02-26 14:24:35 +0530 | [diff] [blame] | 142 | los = kmem_cache_zalloc(lovsub_object_kmem, GFP_NOFS); |
Oleg Drokin | 00697c4 | 2016-02-16 00:46:45 -0500 | [diff] [blame] | 143 | if (los) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 144 | struct cl_object_header *hdr; |
| 145 | |
| 146 | obj = lovsub2lu(los); |
| 147 | hdr = &los->lso_header; |
| 148 | cl_object_header_init(hdr); |
| 149 | lu_object_init(obj, &hdr->coh_lu, dev); |
| 150 | lu_object_add_top(&hdr->coh_lu, obj); |
| 151 | los->lso_cl.co_ops = &lovsub_ops; |
| 152 | obj->lo_ops = &lovsub_lu_obj_ops; |
Oleg Drokin | da5ecb4 | 2016-04-01 15:18:01 -0400 | [diff] [blame] | 153 | } else { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 154 | obj = NULL; |
Oleg Drokin | da5ecb4 | 2016-04-01 15:18:01 -0400 | [diff] [blame] | 155 | } |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 156 | return obj; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /** @} lov */ |