Whamcloud - gitweb
LU-3336 lfsck: recreate the lost MDT-object
[fs/lustre-release.git] / lustre / ofd / ofd_io.c
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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2013, 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  * lustre/ofd/ofd_io.c
37  *
38  * Author: Alex Tomas <bzzz@whamcloud.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_FILTER
42
43 #include "ofd_internal.h"
44
45 static int ofd_preprw_read(const struct lu_env *env, struct obd_export *exp,
46                            struct ofd_device *ofd, const struct lu_fid *fid,
47                            struct lu_attr *la, int niocount,
48                            struct niobuf_remote *rnb, int *nr_local,
49                            struct niobuf_local *lnb, char *jobid)
50 {
51         struct ofd_object       *fo;
52         int                      i, j, rc, tot_bytes = 0;
53
54         ENTRY;
55         LASSERT(env != NULL);
56
57         fo = ofd_object_find(env, ofd, fid);
58         if (IS_ERR(fo))
59                 RETURN(PTR_ERR(fo));
60         LASSERT(fo != NULL);
61
62         ofd_read_lock(env, fo);
63         if (!ofd_object_exists(fo))
64                 GOTO(unlock, rc = -ENOENT);
65
66         /* parse remote buffers to local buffers and prepare the latter */
67         *nr_local = 0;
68         for (i = 0, j = 0; i < niocount; i++) {
69                 rc = dt_bufs_get(env, ofd_object_child(fo), rnb + i,
70                                  lnb + j, 0, ofd_object_capa(env, fo));
71                 if (unlikely(rc < 0))
72                         GOTO(buf_put, rc);
73                 LASSERT(rc <= PTLRPC_MAX_BRW_PAGES);
74                 /* correct index for local buffers to continue with */
75                 j += rc;
76                 *nr_local += rc;
77                 LASSERT(j <= PTLRPC_MAX_BRW_PAGES);
78                 tot_bytes += rnb[i].rnb_len;
79         }
80
81         LASSERT(*nr_local > 0 && *nr_local <= PTLRPC_MAX_BRW_PAGES);
82         rc = dt_attr_get(env, ofd_object_child(fo), la,
83                          ofd_object_capa(env, fo));
84         if (unlikely(rc))
85                 GOTO(buf_put, rc);
86
87         rc = dt_read_prep(env, ofd_object_child(fo), lnb, *nr_local);
88         if (unlikely(rc))
89                 GOTO(buf_put, rc);
90
91         ofd_counter_incr(exp, LPROC_OFD_STATS_READ, jobid, tot_bytes);
92         RETURN(0);
93
94 buf_put:
95         dt_bufs_put(env, ofd_object_child(fo), lnb, *nr_local);
96 unlock:
97         ofd_read_unlock(env, fo);
98         ofd_object_put(env, fo);
99         return rc;
100 }
101
102 static int ofd_preprw_write(const struct lu_env *env, struct obd_export *exp,
103                             struct ofd_device *ofd, const struct lu_fid *fid,
104                             struct lu_attr *la, struct obdo *oa,
105                             int objcount, struct obd_ioobj *obj,
106                             struct niobuf_remote *rnb, int *nr_local,
107                             struct niobuf_local *lnb, char *jobid)
108 {
109         struct ofd_object       *fo;
110         int                      i, j, k, rc = 0, tot_bytes = 0;
111
112         ENTRY;
113         LASSERT(env != NULL);
114         LASSERT(objcount == 1);
115
116         if (unlikely(exp->exp_obd->obd_recovering)) {
117                 struct ofd_thread_info *info = ofd_info(env);
118
119                 /* copied from ofd_precreate_object */
120                 /* XXX this should be consolidated to use the same code
121                  *     instead of a copy, due to the ongoing risk of bugs. */
122                 memset(&info->fti_attr, 0, sizeof(info->fti_attr));
123                 info->fti_attr.la_valid = LA_TYPE | LA_MODE;
124                 info->fti_attr.la_mode = S_IFREG | S_ISUID | S_ISGID | 0666;
125                 info->fti_attr.la_valid |= LA_ATIME | LA_MTIME | LA_CTIME;
126                 /* Initialize a/c/m time so any client timestamp will always
127                  * be newer and update the inode. ctime = 0 is also handled
128                  * specially in osd_inode_setattr().  See LU-221, LU-1042 */
129                 info->fti_attr.la_atime = 0;
130                 info->fti_attr.la_mtime = 0;
131                 info->fti_attr.la_ctime = 0;
132
133                 fo = ofd_object_find_or_create(env, ofd, fid, &info->fti_attr);
134         } else {
135                 fo = ofd_object_find(env, ofd, fid);
136         }
137
138         if (IS_ERR(fo))
139                 GOTO(out, rc = PTR_ERR(fo));
140         LASSERT(fo != NULL);
141
142         ofd_read_lock(env, fo);
143         if (!ofd_object_exists(fo)) {
144                 CERROR("%s: BRW to missing obj "DOSTID"\n",
145                        exp->exp_obd->obd_name, POSTID(&obj->ioo_oid));
146                 ofd_read_unlock(env, fo);
147                 ofd_object_put(env, fo);
148                 GOTO(out, rc = -ENOENT);
149         }
150
151         /* Process incoming grant info, set OBD_BRW_GRANTED flag and grant some
152          * space back if possible */
153         ofd_grant_prepare_write(env, exp, oa, rnb, obj->ioo_bufcnt);
154
155         /* parse remote buffers to local buffers and prepare the latter */
156         *nr_local = 0;
157         for (i = 0, j = 0; i < obj->ioo_bufcnt; i++) {
158                 rc = dt_bufs_get(env, ofd_object_child(fo),
159                                  rnb + i, lnb + j, 1,
160                                  ofd_object_capa(env, fo));
161                 if (unlikely(rc < 0))
162                         GOTO(err, rc);
163                 LASSERT(rc <= PTLRPC_MAX_BRW_PAGES);
164                 /* correct index for local buffers to continue with */
165                 for (k = 0; k < rc; k++) {
166                         lnb[j+k].lnb_flags = rnb[i].rnb_flags;
167                         if (!(rnb[i].rnb_flags & OBD_BRW_GRANTED))
168                                 lnb[j+k].lnb_rc = -ENOSPC;
169
170                         /* remote client can't break through quota */
171                         if (exp_connect_rmtclient(exp))
172                                 lnb[j+k].lnb_flags &= ~OBD_BRW_NOQUOTA;
173                 }
174                 j += rc;
175                 *nr_local += rc;
176                 LASSERT(j <= PTLRPC_MAX_BRW_PAGES);
177                 tot_bytes += rnb[i].rnb_len;
178         }
179         LASSERT(*nr_local > 0 && *nr_local <= PTLRPC_MAX_BRW_PAGES);
180
181         rc = dt_write_prep(env, ofd_object_child(fo), lnb, *nr_local);
182         if (unlikely(rc != 0))
183                 GOTO(err, rc);
184
185         ofd_counter_incr(exp, LPROC_OFD_STATS_WRITE, jobid, tot_bytes);
186         RETURN(0);
187 err:
188         dt_bufs_put(env, ofd_object_child(fo), lnb, *nr_local);
189         ofd_read_unlock(env, fo);
190         /* ofd_grant_prepare_write() was called, so we must commit */
191         ofd_grant_commit(env, exp, rc);
192 out:
193         /* let's still process incoming grant information packed in the oa,
194          * but without enforcing grant since we won't proceed with the write.
195          * Just like a read request actually. */
196         ofd_grant_prepare_read(env, exp, oa);
197         return rc;
198 }
199
200 int ofd_preprw(const struct lu_env *env, int cmd, struct obd_export *exp,
201                struct obdo *oa, int objcount, struct obd_ioobj *obj,
202                struct niobuf_remote *rnb, int *nr_local,
203                struct niobuf_local *lnb, struct obd_trans_info *oti,
204                struct lustre_capa *capa)
205 {
206         struct tgt_session_info *tsi = tgt_ses_info(env);
207         struct ofd_device       *ofd = ofd_exp(exp);
208         struct ofd_thread_info  *info;
209         char                    *jobid;
210         const struct lu_fid     *fid = &oa->o_oi.oi_fid;
211         int                      rc = 0;
212
213         if (*nr_local > PTLRPC_MAX_BRW_PAGES) {
214                 CERROR("%s: bulk has too many pages %d, which exceeds the"
215                        "maximum pages per RPC of %d\n",
216                        exp->exp_obd->obd_name, *nr_local, PTLRPC_MAX_BRW_PAGES);
217                 RETURN(-EPROTO);
218         }
219
220         if (tgt_ses_req(tsi) == NULL) { /* echo client case */
221                 LASSERT(oti != NULL);
222                 info = ofd_info_init(env, exp);
223                 ofd_oti2info(info, oti);
224                 jobid = oti->oti_jobid;
225         } else {
226                 info = tsi2ofd_info(tsi);
227                 jobid = tsi->tsi_jobid;
228         }
229
230         LASSERT(oa != NULL);
231
232         if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT)) {
233                 struct ofd_seq          *oseq;
234
235                 oseq = ofd_seq_load(env, ofd, ostid_seq(&oa->o_oi));
236                 if (IS_ERR(oseq)) {
237                         CERROR("%s: Can not find seq for "DOSTID
238                                ": rc = %ld\n", ofd_name(ofd), POSTID(&oa->o_oi),
239                                PTR_ERR(oseq));
240                         RETURN(-EINVAL);
241                 }
242
243                 if (oseq->os_destroys_in_progress == 0) {
244                         /* don't fail lookups for orphan recovery, it causes
245                          * later LBUGs when objects still exist during
246                          * precreate */
247                         ofd_seq_put(env, oseq);
248                         RETURN(-ENOENT);
249                 }
250                 ofd_seq_put(env, oseq);
251         }
252
253         LASSERT(objcount == 1);
254         LASSERT(obj->ioo_bufcnt > 0);
255
256         if (cmd == OBD_BRW_WRITE) {
257                 rc = ofd_auth_capa(exp, fid, ostid_seq(&oa->o_oi),
258                                    capa, CAPA_OPC_OSS_WRITE);
259                 if (rc == 0) {
260                         la_from_obdo(&info->fti_attr, oa, OBD_MD_FLGETATTR);
261                         rc = ofd_preprw_write(env, exp, ofd, fid,
262                                               &info->fti_attr, oa, objcount,
263                                               obj, rnb, nr_local, lnb, jobid);
264                 }
265         } else if (cmd == OBD_BRW_READ) {
266                 rc = ofd_auth_capa(exp, fid, ostid_seq(&oa->o_oi),
267                                    capa, CAPA_OPC_OSS_READ);
268                 if (rc == 0) {
269                         ofd_grant_prepare_read(env, exp, oa);
270                         rc = ofd_preprw_read(env, exp, ofd, fid,
271                                              &info->fti_attr, obj->ioo_bufcnt,
272                                              rnb, nr_local, lnb, jobid);
273                         obdo_from_la(oa, &info->fti_attr, LA_ATIME);
274                 }
275         } else {
276                 CERROR("%s: wrong cmd %d received!\n",
277                        exp->exp_obd->obd_name, cmd);
278                 rc = -EPROTO;
279         }
280         RETURN(rc);
281 }
282
283 static int
284 ofd_commitrw_read(const struct lu_env *env, struct ofd_device *ofd,
285                   const struct lu_fid *fid, int objcount, int niocount,
286                   struct niobuf_local *lnb)
287 {
288         struct ofd_object *fo;
289
290         ENTRY;
291
292         LASSERT(niocount > 0);
293
294         fo = ofd_object_find(env, ofd, fid);
295         if (IS_ERR(fo))
296                 RETURN(PTR_ERR(fo));
297         LASSERT(fo != NULL);
298         LASSERT(ofd_object_exists(fo));
299         dt_bufs_put(env, ofd_object_child(fo), lnb, niocount);
300
301         ofd_read_unlock(env, fo);
302         ofd_object_put(env, fo);
303         /* second put is pair to object_get in ofd_preprw_read */
304         ofd_object_put(env, fo);
305
306         RETURN(0);
307 }
308
309 static int
310 ofd_write_attr_set(const struct lu_env *env, struct ofd_device *ofd,
311                    struct ofd_object *ofd_obj, struct lu_attr *la,
312                    struct filter_fid *ff)
313 {
314         struct ofd_thread_info  *info = ofd_info(env);
315         __u64                    valid = la->la_valid;
316         int                      rc;
317         struct thandle          *th;
318         struct dt_object        *dt_obj;
319         int                      ff_needed = 0;
320
321         ENTRY;
322
323         LASSERT(la);
324
325         dt_obj = ofd_object_child(ofd_obj);
326         LASSERT(dt_obj != NULL);
327
328         la->la_valid &= LA_UID | LA_GID;
329
330         rc = ofd_attr_handle_ugid(env, ofd_obj, la, 0 /* !is_setattr */);
331         if (rc != 0)
332                 GOTO(out, rc);
333
334         if (ff != NULL) {
335                 rc = ofd_object_ff_check(env, ofd_obj);
336                 if (rc == -ENODATA)
337                         ff_needed = 1;
338                 else if (rc < 0)
339                         GOTO(out, rc);
340         }
341
342         if (!la->la_valid && !ff_needed)
343                 /* no attributes to set */
344                 GOTO(out, rc = 0);
345
346         th = ofd_trans_create(env, ofd);
347         if (IS_ERR(th))
348                 GOTO(out, rc = PTR_ERR(th));
349
350         if (la->la_valid) {
351                 rc = dt_declare_attr_set(env, dt_obj, la, th);
352                 if (rc)
353                         GOTO(out_tx, rc);
354         }
355
356         if (ff_needed) {
357                 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_UNMATCHED_PAIR1))
358                         ff->ff_parent.f_oid = cpu_to_le32(1UL << 31);
359                 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_UNMATCHED_PAIR2))
360                         ff->ff_parent.f_oid =
361                         cpu_to_le32(le32_to_cpu(ff->ff_parent.f_oid) - 1);
362
363                 info->fti_buf.lb_buf = ff;
364                 info->fti_buf.lb_len = sizeof(*ff);
365                 rc = dt_declare_xattr_set(env, dt_obj, &info->fti_buf,
366                                           XATTR_NAME_FID, 0, th);
367                 if (rc)
368                         GOTO(out_tx, rc);
369         }
370
371         /* We don't need a transno for this operation which will be re-executed
372          * anyway when the OST_WRITE (with a transno assigned) is replayed */
373         rc = dt_trans_start_local(env, ofd->ofd_osd , th);
374         if (rc)
375                 GOTO(out_tx, rc);
376
377         /* set uid/gid */
378         if (la->la_valid) {
379                 rc = dt_attr_set(env, dt_obj, la, th,
380                                  ofd_object_capa(env, ofd_obj));
381                 if (rc)
382                         GOTO(out_tx, rc);
383         }
384
385         /* set filter fid EA */
386         if (ff_needed) {
387                 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NOPFID))
388                         GOTO(out_tx, rc);
389
390                 rc = dt_xattr_set(env, dt_obj, &info->fti_buf, XATTR_NAME_FID,
391                                   0, th, BYPASS_CAPA);
392                 if (rc)
393                         GOTO(out_tx, rc);
394         }
395
396         EXIT;
397 out_tx:
398         dt_trans_stop(env, ofd->ofd_osd, th);
399 out:
400         la->la_valid = valid;
401         return rc;
402 }
403
404 struct ofd_soft_sync_callback {
405         struct dt_txn_commit_cb  ossc_cb;
406         struct obd_export       *ossc_exp;
407 };
408
409 static void ofd_cb_soft_sync(struct lu_env *env, struct thandle *th,
410                              struct dt_txn_commit_cb *cb, int err)
411 {
412         struct ofd_soft_sync_callback   *ossc;
413
414         ossc = container_of(cb, struct ofd_soft_sync_callback, ossc_cb);
415
416         CDEBUG(D_INODE, "export %p soft sync count is reset\n", ossc->ossc_exp);
417         atomic_set(&ossc->ossc_exp->exp_filter_data.fed_soft_sync_count, 0);
418
419         class_export_cb_put(ossc->ossc_exp);
420         OBD_FREE_PTR(ossc);
421 }
422
423 static int ofd_soft_sync_cb_add(struct thandle *th, struct obd_export *exp)
424 {
425         struct ofd_soft_sync_callback           *ossc;
426         struct dt_txn_commit_cb                 *dcb;
427         int                                      rc;
428
429         OBD_ALLOC_PTR(ossc);
430         if (ossc == NULL)
431                 return -ENOMEM;
432
433         ossc->ossc_exp = class_export_cb_get(exp);
434
435         dcb = &ossc->ossc_cb;
436         dcb->dcb_func = ofd_cb_soft_sync;
437         CFS_INIT_LIST_HEAD(&dcb->dcb_linkage);
438         strncpy(dcb->dcb_name, "ofd_cb_soft_sync", MAX_COMMIT_CB_STR_LEN);
439         dcb->dcb_name[MAX_COMMIT_CB_STR_LEN - 1] = '\0';
440
441         rc = dt_trans_cb_add(th, dcb);
442         if (rc) {
443                 class_export_cb_put(exp);
444                 OBD_FREE_PTR(ossc);
445         }
446
447         return rc;
448 }
449
450 static int
451 ofd_commitrw_write(const struct lu_env *env, struct obd_export *exp,
452                    struct ofd_device *ofd, const struct lu_fid *fid,
453                    struct lu_attr *la, struct filter_fid *ff, int objcount,
454                    int niocount, struct niobuf_local *lnb, int old_rc)
455 {
456         struct ofd_thread_info  *info = ofd_info(env);
457         struct ofd_object       *fo;
458         struct dt_object        *o;
459         struct thandle          *th;
460         int                      rc = 0;
461         int                      retries = 0;
462         int                      i;
463         struct filter_export_data *fed = &exp->exp_filter_data;
464         bool                     soft_sync = false;
465         bool                     cb_registered = false;
466
467         ENTRY;
468
469         LASSERT(objcount == 1);
470
471         fo = ofd_object_find(env, ofd, fid);
472         LASSERT(fo != NULL);
473         LASSERT(ofd_object_exists(fo));
474
475         o = ofd_object_child(fo);
476         LASSERT(o != NULL);
477
478         if (old_rc)
479                 GOTO(out, rc = old_rc);
480
481         /*
482          * The first write to each object must set some attributes.  It is
483          * important to set the uid/gid before calling
484          * dt_declare_write_commit() since quota enforcement is now handled in
485          * declare phases.
486          */
487         rc = ofd_write_attr_set(env, ofd, fo, la, ff);
488         if (rc)
489                 GOTO(out, rc);
490
491         la->la_valid &= LA_ATIME | LA_MTIME | LA_CTIME;
492
493 retry:
494         th = ofd_trans_create(env, ofd);
495         if (IS_ERR(th))
496                 GOTO(out, rc = PTR_ERR(th));
497
498         th->th_sync |= ofd->ofd_syncjournal;
499         if (th->th_sync == 0) {
500                 for (i = 0; i < niocount; i++) {
501                         if (!(lnb[i].lnb_flags & OBD_BRW_ASYNC)) {
502                                 th->th_sync = 1;
503                                 break;
504                         }
505                         if (lnb[i].lnb_flags & OBD_BRW_SOFT_SYNC)
506                                 soft_sync = true;
507                 }
508         }
509
510         if (OBD_FAIL_CHECK(OBD_FAIL_OST_DQACQ_NET))
511                 GOTO(out_stop, rc = -EINPROGRESS);
512
513         rc = dt_declare_write_commit(env, o, lnb, niocount, th);
514         if (rc)
515                 GOTO(out_stop, rc);
516
517         if (la->la_valid) {
518                 /* update [mac]time if needed */
519                 rc = dt_declare_attr_set(env, o, la, th);
520                 if (rc)
521                         GOTO(out_stop, rc);
522         }
523
524         rc = ofd_trans_start(env, ofd, fo, th);
525         if (rc)
526                 GOTO(out_stop, rc);
527
528         rc = dt_write_commit(env, o, lnb, niocount, th);
529         if (rc)
530                 GOTO(out_stop, rc);
531
532         if (la->la_valid) {
533                 rc = dt_attr_set(env, o, la, th, ofd_object_capa(env, fo));
534                 if (rc)
535                         GOTO(out_stop, rc);
536         }
537
538         /* get attr to return */
539         rc = dt_attr_get(env, o, la, ofd_object_capa(env, fo));
540
541 out_stop:
542         /* Force commit to make the just-deleted blocks
543          * reusable. LU-456 */
544         if (rc == -ENOSPC)
545                 th->th_sync = 1;
546
547         /* do this before trans stop in case commit has finished */
548         if (!th->th_sync && soft_sync && !cb_registered) {
549                 ofd_soft_sync_cb_add(th, exp);
550                 cb_registered = true;
551         }
552
553         ofd_trans_stop(env, ofd, th, rc);
554         if (rc == -ENOSPC && retries++ < 3) {
555                 CDEBUG(D_INODE, "retry after force commit, retries:%d\n",
556                        retries);
557                 goto retry;
558         }
559
560         if (!soft_sync)
561                 /* reset fed_soft_sync_count upon non-SOFT_SYNC RPC */
562                 atomic_set(&fed->fed_soft_sync_count, 0);
563         else if (atomic_inc_return(&fed->fed_soft_sync_count) ==
564                  ofd->ofd_soft_sync_limit)
565                 dt_commit_async(env, ofd->ofd_osd);
566
567 out:
568         dt_bufs_put(env, o, lnb, niocount);
569         ofd_read_unlock(env, fo);
570         ofd_object_put(env, fo);
571         /* second put is pair to object_get in ofd_preprw_write */
572         ofd_object_put(env, fo);
573         ofd_grant_commit(env, info->fti_exp, old_rc);
574         RETURN(rc);
575 }
576
577 int ofd_commitrw(const struct lu_env *env, int cmd, struct obd_export *exp,
578                  struct obdo *oa, int objcount, struct obd_ioobj *obj,
579                  struct niobuf_remote *rnb, int npages,
580                  struct niobuf_local *lnb, struct obd_trans_info *oti,
581                  int old_rc)
582 {
583         struct ofd_thread_info  *info = ofd_info(env);
584         struct ofd_mod_data     *fmd;
585         __u64                    valid;
586         struct ofd_device       *ofd = ofd_exp(exp);
587         struct filter_fid       *ff = NULL;
588         const struct lu_fid     *fid = &oa->o_oi.oi_fid;
589         int                      rc = 0;
590
591         LASSERT(npages > 0);
592
593         if (cmd == OBD_BRW_WRITE) {
594                 /* Don't update timestamps if this write is older than a
595                  * setattr which modifies the timestamps. b=10150 */
596
597                 /* XXX when we start having persistent reservations this needs
598                  * to be changed to ofd_fmd_get() to create the fmd if it
599                  * doesn't already exist so we can store the reservation handle
600                  * there. */
601                 valid = OBD_MD_FLUID | OBD_MD_FLGID;
602                 fmd = ofd_fmd_find(exp, fid);
603                 if (!fmd || fmd->fmd_mactime_xid < info->fti_xid)
604                         valid |= OBD_MD_FLATIME | OBD_MD_FLMTIME |
605                                  OBD_MD_FLCTIME;
606                 ofd_fmd_put(exp, fmd);
607                 la_from_obdo(&info->fti_attr, oa, valid);
608
609                 if (oa->o_valid & OBD_MD_FLFID) {
610                         ff = &info->fti_mds_fid;
611                         ofd_prepare_fidea(ff, oa);
612                 }
613
614                 rc = ofd_commitrw_write(env, exp, ofd, fid, &info->fti_attr,
615                                         ff, objcount, npages, lnb, old_rc);
616                 if (rc == 0)
617                         obdo_from_la(oa, &info->fti_attr,
618                                      OFD_VALID_FLAGS | LA_GID | LA_UID);
619                 else
620                         obdo_from_la(oa, &info->fti_attr, LA_GID | LA_UID);
621
622                 /* don't report overquota flag if we failed before reaching
623                  * commit */
624                 if (old_rc == 0 && (rc == 0 || rc == -EDQUOT)) {
625                         /* return the overquota flags to client */
626                         if (lnb[0].lnb_flags & OBD_BRW_OVER_USRQUOTA) {
627                                 if (oa->o_valid & OBD_MD_FLFLAGS)
628                                         oa->o_flags |= OBD_FL_NO_USRQUOTA;
629                                 else
630                                         oa->o_flags = OBD_FL_NO_USRQUOTA;
631                         }
632
633                         if (lnb[0].lnb_flags & OBD_BRW_OVER_GRPQUOTA) {
634                                 if (oa->o_valid & OBD_MD_FLFLAGS)
635                                         oa->o_flags |= OBD_FL_NO_GRPQUOTA;
636                                 else
637                                         oa->o_flags = OBD_FL_NO_GRPQUOTA;
638                         }
639
640                         oa->o_valid |= OBD_MD_FLFLAGS;
641                         oa->o_valid |= OBD_MD_FLUSRQUOTA | OBD_MD_FLGRPQUOTA;
642                 }
643         } else if (cmd == OBD_BRW_READ) {
644                 struct ldlm_namespace *ns = ofd->ofd_namespace;
645
646                 /* If oa != NULL then ofd_preprw_read updated the inode
647                  * atime and we should update the lvb so that other glimpses
648                  * will also get the updated value. bug 5972 */
649                 if (oa && ns && ns->ns_lvbo && ns->ns_lvbo->lvbo_update) {
650                          struct ldlm_resource *rs = NULL;
651
652                         ost_fid_build_resid(fid, &info->fti_resid);
653                         rs = ldlm_resource_get(ns, NULL, &info->fti_resid,
654                                                LDLM_EXTENT, 0);
655                         if (rs != NULL) {
656                                 ns->ns_lvbo->lvbo_update(rs, NULL, 1);
657                                 ldlm_resource_putref(rs);
658                         }
659                 }
660                 rc = ofd_commitrw_read(env, ofd, fid, objcount,
661                                        npages, lnb);
662                 if (old_rc)
663                         rc = old_rc;
664         } else {
665                 LBUG();
666                 rc = -EPROTO;
667         }
668
669         if (oti != NULL)
670                 ofd_info2oti(info, oti);
671         RETURN(rc);
672 }