Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[fs/lustre-release.git] / lustre / ofd / ofd_trans.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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2014, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * lustre/ofd/ofd_trans.c
32  *
33  * This file provides functions for OBD Filter Device (OFD) transaction
34  * management.
35  *
36  * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
37  * Author: Mikhail Pershin <mike.pershin@intel.com>
38  */
39
40 #define DEBUG_SUBSYSTEM S_FILTER
41
42 #include "ofd_internal.h"
43
44 /**
45  * Create new transaction in OFD.
46  *
47  * This function creates a transaction with dt_trans_create()
48  * and makes it synchronous if required by the export state.
49  *
50  * \param[in] env       execution environment
51  * \param[in] ofd       OFD device
52  *
53  * \retval              struct thandle if transaction was created successfully
54  * \retval              ERR_PTR on negative value in case of error
55  */
56 struct thandle *ofd_trans_create(const struct lu_env *env,
57                                  struct ofd_device *ofd)
58 {
59         struct ofd_thread_info  *info = ofd_info(env);
60         struct thandle          *th;
61
62         LASSERT(info);
63
64         th = dt_trans_create(env, ofd->ofd_osd);
65         if (IS_ERR(th))
66                 return th;
67
68         /* export can require sync operations */
69         if (info->fti_exp != NULL)
70                 th->th_sync |= info->fti_exp->exp_need_sync;
71         return th;
72 }
73
74 /**
75  * Start transaction in OFD.
76  *
77  * This function updates the given \a obj object version and calls
78  * dt_trans_start().
79  *
80  * \param[in] env       execution environment
81  * \param[in] ofd       OFD device
82  * \param[in] obj       OFD object affected by this transaction
83  * \param[in] th        transaction handle
84  *
85  * \retval              0 if successful
86  * \retval              negative value in case of error
87  */
88 int ofd_trans_start(const struct lu_env *env, struct ofd_device *ofd,
89                     struct ofd_object *obj, struct thandle *th)
90 {
91         /* version change is required for this object */
92         if (obj != NULL)
93                 tgt_vbr_obj_set(env, ofd_object_child(obj));
94
95         return dt_trans_start(env, ofd->ofd_osd, th);
96 }
97
98 /**
99  * Stop transaction in OFD.
100  *
101  * This function fills thandle::th_result with result of whole operation
102  * and calls dt_trans_stop().
103  *
104  * \param[in] env       execution environment
105  * \param[in] ofd       OFD device
106  * \param[in] th        transaction handle
107  * \param[in] rc        result code of whole operation
108  *
109  * \retval              0 if successful
110  * \retval              negative value if case of error
111  */
112 int ofd_trans_stop(const struct lu_env *env, struct ofd_device *ofd,
113                     struct thandle *th, int rc)
114 {
115         th->th_result = rc;
116         return dt_trans_stop(env, ofd->ofd_osd, th);
117 }