Whamcloud - gitweb
17b6866e0e3b8332a0f43489fa947ffbcb02c624
[fs/lustre-release.git] / lustre / llite / vvp_req.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.gnu.org/licenses/gpl-2.0.html
19  *
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  *
26  * Copyright (c) 2011, 2014, Intel Corporation.
27  */
28
29 #define DEBUG_SUBSYSTEM S_LLITE
30
31 #include <lustre/lustre_idl.h>
32 #include <cl_object.h>
33 #include <obd.h>
34 #include <obd_support.h>
35 #include "llite_internal.h"
36 #include "vvp_internal.h"
37
38 static inline struct vvp_req *cl2vvp_req(const struct cl_req_slice *slice)
39 {
40         return container_of0(slice, struct vvp_req, vrq_cl);
41 }
42
43 /**
44  * Implementation of struct cl_req_operations::cro_attr_set() for VVP
45  * layer. VVP is responsible for
46  *
47  *    - o_[mac]time
48  *
49  *    - o_mode
50  *
51  *    - o_parent_seq
52  *
53  *    - o_[ug]id
54  *
55  *    - o_parent_oid
56  *
57  *    - o_parent_ver
58  *
59  *  and capability.
60  */
61 static void vvp_req_attr_set(const struct lu_env *env,
62                              const struct cl_req_slice *slice,
63                              const struct cl_object *obj,
64                              struct cl_req_attr *attr, u64 flags)
65 {
66         struct inode    *inode;
67         struct obdo     *oa;
68         u32              valid_flags;
69
70         oa = attr->cra_oa;
71         inode = vvp_object_inode(obj);
72         valid_flags = OBD_MD_FLTYPE;
73
74         if ((flags & OBD_MD_FLOSSCAPA) != 0) {
75                 LASSERT(attr->cra_capa == NULL);
76                 attr->cra_capa = cl_capa_lookup(inode,
77                                                 slice->crs_req->crq_type);
78         }
79
80         if (slice->crs_req->crq_type == CRT_WRITE) {
81                 valid_flags |= OBD_MD_FLMTIME | OBD_MD_FLCTIME |
82                                OBD_MD_FLUID | OBD_MD_FLGID;
83         }
84
85         obdo_from_inode(oa, inode, valid_flags & flags);
86         obdo_set_parent_fid(oa, &ll_i2info(inode)->lli_fid);
87         if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_INVALID_PFID))
88                 oa->o_parent_oid++;
89
90         memcpy(attr->cra_jobid, ll_i2info(inode)->lli_jobid,
91                LUSTRE_JOBID_SIZE);
92 }
93
94 static void vvp_req_completion(const struct lu_env *env,
95                                const struct cl_req_slice *slice, int ioret)
96 {
97         struct vvp_req *vrq;
98
99         if (ioret > 0)
100                 cl_stats_tally(slice->crs_dev, slice->crs_req->crq_type, ioret);
101
102         vrq = cl2vvp_req(slice);
103         OBD_SLAB_FREE_PTR(vrq, vvp_req_kmem);
104 }
105
106 static const struct cl_req_operations vvp_req_ops = {
107         .cro_attr_set   = vvp_req_attr_set,
108         .cro_completion = vvp_req_completion,
109 };
110
111 int vvp_req_init(const struct lu_env *env, struct cl_device *dev,
112                  struct cl_req *req)
113 {
114         struct vvp_req *vrq;
115         int result;
116
117         OBD_SLAB_ALLOC_PTR_GFP(vrq, vvp_req_kmem, GFP_NOFS);
118         if (vrq != NULL) {
119                 cl_req_slice_add(req, &vrq->vrq_cl, dev, &vvp_req_ops);
120                 result = 0;
121         } else {
122                 result = -ENOMEM;
123         }
124
125         return result;
126 }