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