• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 
37 #define DEBUG_SUBSYSTEM S_LOV
38 
39 #include "../../include/linux/libcfs/libcfs.h"
40 
41 #include "../include/obd_class.h"
42 #include "lov_internal.h"
43 
44 /** Merge the lock value block(&lvb) attributes and KMS from each of the
45  * stripes in a file into a single lvb. It is expected that the caller
46  * initializes the current atime, mtime, ctime to avoid regressing a more
47  * uptodate time on the local client.
48  */
lov_merge_lvb_kms(struct lov_stripe_md * lsm,struct ost_lvb * lvb,__u64 * kms_place)49 int lov_merge_lvb_kms(struct lov_stripe_md *lsm,
50 		      struct ost_lvb *lvb, __u64 *kms_place)
51 {
52 	__u64 size = 0;
53 	__u64 kms = 0;
54 	__u64 blocks = 0;
55 	s64 current_mtime = lvb->lvb_mtime;
56 	s64 current_atime = lvb->lvb_atime;
57 	s64 current_ctime = lvb->lvb_ctime;
58 	int i;
59 	int rc = 0;
60 
61 	assert_spin_locked(&lsm->lsm_lock);
62 	LASSERT(lsm->lsm_lock_owner == current_pid());
63 
64 	CDEBUG(D_INODE, "MDT ID "DOSTID" initial value: s=%llu m=%llu a=%llu c=%llu b=%llu\n",
65 	       POSTID(&lsm->lsm_oi), lvb->lvb_size, lvb->lvb_mtime,
66 	       lvb->lvb_atime, lvb->lvb_ctime, lvb->lvb_blocks);
67 	for (i = 0; i < lsm->lsm_stripe_count; i++) {
68 		struct lov_oinfo *loi = lsm->lsm_oinfo[i];
69 		u64 lov_size, tmpsize;
70 
71 		if (OST_LVB_IS_ERR(loi->loi_lvb.lvb_blocks)) {
72 			rc = OST_LVB_GET_ERR(loi->loi_lvb.lvb_blocks);
73 			continue;
74 		}
75 
76 		tmpsize = loi->loi_kms;
77 		lov_size = lov_stripe_size(lsm, tmpsize, i);
78 		if (lov_size > kms)
79 			kms = lov_size;
80 
81 		if (loi->loi_lvb.lvb_size > tmpsize)
82 			tmpsize = loi->loi_lvb.lvb_size;
83 
84 		lov_size = lov_stripe_size(lsm, tmpsize, i);
85 		if (lov_size > size)
86 			size = lov_size;
87 		/* merge blocks, mtime, atime */
88 		blocks += loi->loi_lvb.lvb_blocks;
89 		if (loi->loi_lvb.lvb_mtime > current_mtime)
90 			current_mtime = loi->loi_lvb.lvb_mtime;
91 		if (loi->loi_lvb.lvb_atime > current_atime)
92 			current_atime = loi->loi_lvb.lvb_atime;
93 		if (loi->loi_lvb.lvb_ctime > current_ctime)
94 			current_ctime = loi->loi_lvb.lvb_ctime;
95 
96 		CDEBUG(D_INODE, "MDT ID "DOSTID" on OST[%u]: s=%llu m=%llu a=%llu c=%llu b=%llu\n",
97 		       POSTID(&lsm->lsm_oi), loi->loi_ost_idx,
98 		       loi->loi_lvb.lvb_size, loi->loi_lvb.lvb_mtime,
99 		       loi->loi_lvb.lvb_atime, loi->loi_lvb.lvb_ctime,
100 		       loi->loi_lvb.lvb_blocks);
101 	}
102 
103 	*kms_place = kms;
104 	lvb->lvb_size = size;
105 	lvb->lvb_blocks = blocks;
106 	lvb->lvb_mtime = current_mtime;
107 	lvb->lvb_atime = current_atime;
108 	lvb->lvb_ctime = current_ctime;
109 	return rc;
110 }
111 
112 /* Must be called under the lov_stripe_lock() */
lov_adjust_kms(struct obd_export * exp,struct lov_stripe_md * lsm,u64 size,int shrink)113 int lov_adjust_kms(struct obd_export *exp, struct lov_stripe_md *lsm,
114 		   u64 size, int shrink)
115 {
116 	struct lov_oinfo *loi;
117 	int stripe = 0;
118 	__u64 kms;
119 
120 	assert_spin_locked(&lsm->lsm_lock);
121 	LASSERT(lsm->lsm_lock_owner == current_pid());
122 
123 	if (shrink) {
124 		for (; stripe < lsm->lsm_stripe_count; stripe++) {
125 			struct lov_oinfo *loi = lsm->lsm_oinfo[stripe];
126 
127 			kms = lov_size_to_stripe(lsm, size, stripe);
128 			CDEBUG(D_INODE,
129 			       "stripe %d KMS %sing %llu->%llu\n",
130 			       stripe, kms > loi->loi_kms ? "increase":"shrink",
131 			       loi->loi_kms, kms);
132 			loi_kms_set(loi, loi->loi_lvb.lvb_size = kms);
133 		}
134 		return 0;
135 	}
136 
137 	if (size > 0)
138 		stripe = lov_stripe_number(lsm, size - 1);
139 	kms = lov_size_to_stripe(lsm, size, stripe);
140 	loi = lsm->lsm_oinfo[stripe];
141 
142 	CDEBUG(D_INODE, "stripe %d KMS %sincreasing %llu->%llu\n",
143 	       stripe, kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms);
144 	if (kms > loi->loi_kms)
145 		loi_kms_set(loi, kms);
146 
147 	return 0;
148 }
149 
lov_merge_attrs(struct obdo * tgt,struct obdo * src,u64 valid,struct lov_stripe_md * lsm,int stripeno,int * set)150 void lov_merge_attrs(struct obdo *tgt, struct obdo *src, u64 valid,
151 		     struct lov_stripe_md *lsm, int stripeno, int *set)
152 {
153 	valid &= src->o_valid;
154 
155 	if (*set) {
156 		if (valid & OBD_MD_FLSIZE) {
157 			/* this handles sparse files properly */
158 			u64 lov_size;
159 
160 			lov_size = lov_stripe_size(lsm, src->o_size, stripeno);
161 			if (lov_size > tgt->o_size)
162 				tgt->o_size = lov_size;
163 		}
164 		if (valid & OBD_MD_FLBLOCKS)
165 			tgt->o_blocks += src->o_blocks;
166 		if (valid & OBD_MD_FLBLKSZ)
167 			tgt->o_blksize += src->o_blksize;
168 		if (valid & OBD_MD_FLCTIME && tgt->o_ctime < src->o_ctime)
169 			tgt->o_ctime = src->o_ctime;
170 		if (valid & OBD_MD_FLMTIME && tgt->o_mtime < src->o_mtime)
171 			tgt->o_mtime = src->o_mtime;
172 		if (valid & OBD_MD_FLDATAVERSION)
173 			tgt->o_data_version += src->o_data_version;
174 	} else {
175 		memcpy(tgt, src, sizeof(*tgt));
176 		tgt->o_oi = lsm->lsm_oi;
177 		if (valid & OBD_MD_FLSIZE)
178 			tgt->o_size = lov_stripe_size(lsm, src->o_size,
179 						      stripeno);
180 	}
181 
182 	/* data_version needs to be valid on all stripes to be correct! */
183 	if (!(valid & OBD_MD_FLDATAVERSION))
184 		tgt->o_valid &= ~OBD_MD_FLDATAVERSION;
185 
186 	*set += 1;
187 }
188