Whamcloud - gitweb
LU-3534 osp: transfer updates with bulk RPC
[fs/lustre-release.git] / lustre / osp / osp_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) 2014, Intel Corporation.
24  */
25 /*
26  * lustre/osp/osp_trans.c
27  *
28  *
29  * 1. OSP (Object Storage Proxy) transaction methods
30  *
31  * Implement OSP layer transaction related interfaces for the dt_device API
32  * dt_device_operations.
33  *
34  *
35  * 2. Handle asynchronous idempotent operations
36  *
37  * The OSP uses OUT (Object Unified Target) RPC to talk with other server
38  * (MDT or OST) for kinds of operations, such as create, unlink, insert,
39  * delete, lookup, set_(x)attr, get_(x)attr, and etc. To reduce the number
40  * of RPCs, we allow multiple operations to be packaged together in single
41  * OUT RPC.
42  *
43  * For the asynchronous idempotent operations, such as get_(x)attr, related
44  * RPCs will be inserted into an osp_device based shared asynchronous request
45  * queue - osp_device::opd_async_requests. When the queue is full, all the
46  * requests in the queue will be packaged into a single OUT RPC and given to
47  * the ptlrpcd daemon (for sending), then the queue is purged and other new
48  * requests can be inserted into it.
49  *
50  * When the asynchronous idempotent operation inserts the request into the
51  * shared queue, it will register an interpreter. When the packaged OUT RPC
52  * is replied (or failed to be sent out), all the registered interpreters
53  * will be called one by one to handle each own result.
54  *
55  *
56  * There are three kinds of transactions
57  *
58  * 1. Local transaction, all of updates of the transaction are in the local MDT.
59  * 2. Remote transaction, all of updates of the transaction are in one remote
60  * MDT, which only happens in LFSCK now.
61  * 3. Distribute transaction, updates for the transaction are in mulitple MDTs.
62  *
63  * Author: Di Wang <di.wang@intel.com>
64  * Author: Fan, Yong <fan.yong@intel.com>
65  */
66
67 #define DEBUG_SUBSYSTEM S_MDS
68
69 #include <lustre_net.h>
70 #include "osp_internal.h"
71
72 /**
73  * The argument for the interpreter callback of osp request.
74  */
75 struct osp_update_args {
76         struct osp_update_request *oaua_update;
77         atomic_t                 *oaua_count;
78         wait_queue_head_t        *oaua_waitq;
79         bool                      oaua_flow_control;
80 };
81
82 /**
83  * Call back for each update request.
84  */
85 struct osp_update_callback {
86         /* list in the osp_update_request::our_cb_items */
87         struct list_head                 ouc_list;
88
89         /* The target of the async update request. */
90         struct osp_object               *ouc_obj;
91
92         /* The data used by or_interpreter. */
93         void                            *ouc_data;
94
95         /* The interpreter function called after the async request handled. */
96         osp_update_interpreter_t        ouc_interpreter;
97 };
98
99 static struct object_update_request *object_update_request_alloc(size_t size)
100 {
101         struct object_update_request *ourq;
102
103         OBD_ALLOC_LARGE(ourq, size);
104         if (ourq == NULL)
105                 return ERR_PTR(-ENOMEM);
106
107         ourq->ourq_magic = UPDATE_REQUEST_MAGIC;
108         ourq->ourq_count = 0;
109
110         return ourq;
111 }
112
113 /**
114  * Allocate new update request
115  *
116  * Allocate new update request and insert it to the req_update_list.
117  *
118  * \param [in] our      osp_udate_request where to create a new
119  *                      update request
120  *
121  * \retval      0 if creation succeeds.
122  * \retval      negative errno if creation fails.
123  */
124 int osp_object_update_request_create(struct osp_update_request *our,
125                                      size_t size)
126 {
127         struct osp_update_request_sub *ours;
128
129         OBD_ALLOC_PTR(ours);
130         if (ours == NULL)
131                 return -ENOMEM;
132
133         ours->ours_req = object_update_request_alloc(size);
134
135         if (IS_ERR(ours->ours_req)) {
136                 OBD_FREE_PTR(ours);
137                 return -ENOMEM;
138         }
139
140         ours->ours_req_size = size;
141         INIT_LIST_HEAD(&ours->ours_list);
142         list_add_tail(&ours->ours_list, &our->our_req_list);
143
144         return 0;
145 }
146
147 /**
148  * Get current update request
149  *
150  * Get current object update request from our_req_list in
151  * osp_update_request, because we always insert the new update
152  * request in the last position, so the last update request
153  * in the list will be the current update req.
154  *
155  * \param[in] our       osp update request where to get the
156  *                      current object update.
157  *
158  * \retval              the current object update.
159  **/
160 struct osp_update_request_sub *
161 osp_current_object_update_request(struct osp_update_request *our)
162 {
163         if (list_empty(&our->our_req_list))
164                 return NULL;
165
166         return list_entry(our->our_req_list.prev, struct osp_update_request_sub,
167                           ours_list);
168 }
169
170 /**
171  * Allocate and initialize osp_update_request
172  *
173  * osp_update_request is being used to track updates being executed on
174  * this dt_device(OSD or OSP). The update buffer will be 4k initially,
175  * and increased if needed.
176  *
177  * \param [in] dt       dt device
178  *
179  * \retval              osp_update_request being allocated if succeed
180  * \retval              ERR_PTR(errno) if failed
181  */
182 struct osp_update_request *osp_update_request_create(struct dt_device *dt)
183 {
184         struct osp_update_request *our;
185
186         OBD_ALLOC_PTR(our);
187         if (our == NULL)
188                 return ERR_PTR(-ENOMEM);
189
190         INIT_LIST_HEAD(&our->our_req_list);
191         INIT_LIST_HEAD(&our->our_cb_items);
192         INIT_LIST_HEAD(&our->our_list);
193
194         osp_object_update_request_create(our, OUT_UPDATE_INIT_BUFFER_SIZE);
195         return our;
196 }
197
198 void osp_update_request_destroy(struct osp_update_request *our)
199 {
200         struct osp_update_request_sub *ours;
201         struct osp_update_request_sub *tmp;
202
203         if (our == NULL)
204                 return;
205
206         list_for_each_entry_safe(ours, tmp, &our->our_req_list, ours_list) {
207                 list_del(&ours->ours_list);
208                 if (ours->ours_req != NULL)
209                         OBD_FREE(ours->ours_req, ours->ours_req_size);
210                 OBD_FREE_PTR(ours);
211         }
212         OBD_FREE_PTR(our);
213 }
214
215 static void
216 object_update_request_dump(const struct object_update_request *ourq,
217                            unsigned int mask)
218 {
219         unsigned int i;
220         size_t total_size = 0;
221
222         for (i = 0; i < ourq->ourq_count; i++) {
223                 struct object_update    *update;
224                 size_t                  size = 0;
225
226                 update = object_update_request_get(ourq, i, &size);
227                 LASSERT(update != NULL);
228                 CDEBUG(mask, "i = %u fid = "DFID" op = %s master = %u"
229                        "params = %d batchid = "LPU64" size = %zu\n",
230                        i, PFID(&update->ou_fid),
231                        update_op_str(update->ou_type),
232                        update->ou_master_index, update->ou_params_count,
233                        update->ou_batchid, size);
234
235                 total_size += size;
236         }
237
238         CDEBUG(mask, "updates = %p magic = %x count = %d size = %zu\n", ourq,
239                ourq->ourq_magic, ourq->ourq_count, total_size);
240 }
241
242 /**
243  * Prepare update request.
244  *
245  * Prepare OUT update ptlrpc request, and the request usually includes
246  * all of updates (stored in \param ureq) from one operation.
247  *
248  * \param[in] env       execution environment
249  * \param[in] imp       import on which ptlrpc request will be sent
250  * \param[in] ureq      hold all of updates which will be packed into the req
251  * \param[in] reqp      request to be created
252  *
253  * \retval              0 if preparation succeeds.
254  * \retval              negative errno if preparation fails.
255  */
256 int osp_prep_update_req(const struct lu_env *env, struct obd_import *imp,
257                         struct osp_update_request *our,
258                         struct ptlrpc_request **reqp)
259 {
260         struct ptlrpc_request           *req;
261         struct ptlrpc_bulk_desc         *desc;
262         struct osp_update_request_sub   *ours;
263         struct out_update_header        *ouh;
264         struct out_update_buffer        *oub;
265         __u32                           buf_count = 0;
266         int                             rc;
267         ENTRY;
268
269         list_for_each_entry(ours, &our->our_req_list, ours_list) {
270                 object_update_request_dump(ours->ours_req, D_INFO);
271                 buf_count++;
272         }
273
274         req = ptlrpc_request_alloc(imp, &RQF_OUT_UPDATE);
275         if (req == NULL)
276                 RETURN(-ENOMEM);
277
278         req_capsule_set_size(&req->rq_pill, &RMF_OUT_UPDATE_BUF, RCL_CLIENT,
279                              buf_count * sizeof(*oub));
280
281         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, OUT_UPDATE);
282         if (rc != 0)
283                 GOTO(out_req, rc);
284
285         ouh = req_capsule_client_get(&req->rq_pill, &RMF_OUT_UPDATE_HEADER);
286         ouh->ouh_magic = OUT_UPDATE_HEADER_MAGIC;
287         ouh->ouh_count = buf_count;
288
289         oub = req_capsule_client_get(&req->rq_pill, &RMF_OUT_UPDATE_BUF);
290         list_for_each_entry(ours, &our->our_req_list, ours_list) {
291                 oub->oub_size = ours->ours_req_size;
292                 oub++;
293         }
294
295         req->rq_bulk_write = 1;
296         desc = ptlrpc_prep_bulk_imp(req, buf_count,
297                 MD_MAX_BRW_SIZE >> LNET_MTU_BITS,
298                 PTLRPC_BULK_GET_SOURCE | PTLRPC_BULK_BUF_KVEC,
299                 MDS_BULK_PORTAL, &ptlrpc_bulk_kvec_ops);
300         if (desc == NULL)
301                 GOTO(out_req, rc = -ENOMEM);
302
303         /* NB req now owns desc and will free it when it gets freed */
304         list_for_each_entry(ours, &our->our_req_list, ours_list)
305                 desc->bd_frag_ops->add_iov_frag(desc, ours->ours_req,
306                                                 ours->ours_req_size);
307
308         req_capsule_set_size(&req->rq_pill, &RMF_OUT_UPDATE_REPLY,
309                              RCL_SERVER, OUT_UPDATE_REPLY_SIZE);
310
311         ptlrpc_request_set_replen(req);
312         req->rq_request_portal = OUT_PORTAL;
313         req->rq_reply_portal = OSC_REPLY_PORTAL;
314         *reqp = req;
315
316 out_req:
317         if (rc < 0)
318                 ptlrpc_req_finished(req);
319
320         RETURN(rc);
321 }
322
323 /**
324  * Send update RPC.
325  *
326  * Send update request to the remote MDT synchronously.
327  *
328  * \param[in] env       execution environment
329  * \param[in] imp       import on which ptlrpc request will be sent
330  * \param[in] our       hold all of updates which will be packed into the req
331  * \param[in] reqp      request to be created
332  *
333  * \retval              0 if RPC succeeds.
334  * \retval              negative errno if RPC fails.
335  */
336
337 int osp_remote_sync(const struct lu_env *env, struct osp_device *osp,
338                     struct osp_update_request *our,
339                     struct ptlrpc_request **reqp)
340 {
341         struct obd_import       *imp = osp->opd_obd->u.cli.cl_import;
342         struct ptlrpc_request   *req = NULL;
343         int                     rc;
344         ENTRY;
345
346         rc = osp_prep_update_req(env, imp, our, &req);
347         if (rc != 0)
348                 RETURN(rc);
349
350         /* This will only be called with read-only update, and these updates
351          * might be used to retrieve update log during recovery process, so
352          * it will be allowed to send during recovery process */
353         req->rq_allow_replay = 1;
354
355         /* Note: some dt index api might return non-zero result here, like
356          * osd_index_ea_lookup, so we should only check rc < 0 here */
357         rc = ptlrpc_queue_wait(req);
358         our->our_rc = rc;
359         if (rc < 0 || reqp == NULL)
360                 ptlrpc_req_finished(req);
361         else
362                 *reqp = req;
363
364         RETURN(rc);
365 }
366
367 static void osp_trans_stop_cb(struct osp_thandle *oth, int result)
368 {
369         struct dt_txn_commit_cb *dcb;
370         struct dt_txn_commit_cb *tmp;
371
372         /* call per-transaction stop callbacks if any */
373         list_for_each_entry_safe(dcb, tmp, &oth->ot_stop_dcb_list,
374                                  dcb_linkage) {
375                 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
376                          "commit callback entry: magic=%x name='%s'\n",
377                          dcb->dcb_magic, dcb->dcb_name);
378                 list_del_init(&dcb->dcb_linkage);
379                 dcb->dcb_func(NULL, &oth->ot_super, dcb, result);
380         }
381 }
382
383 /**
384  * Allocate an osp request and initialize it with the given parameters.
385  *
386  * \param[in] obj               pointer to the operation target
387  * \param[in] data              pointer to the data used by the interpreter
388  * \param[in] interpreter       pointer to the interpreter function
389  *
390  * \retval                      pointer to the asychronous request
391  * \retval                      NULL if the allocation failed
392  */
393 static struct osp_update_callback *
394 osp_update_callback_init(struct osp_object *obj, void *data,
395                          osp_update_interpreter_t interpreter)
396 {
397         struct osp_update_callback *ouc;
398
399         OBD_ALLOC_PTR(ouc);
400         if (ouc == NULL)
401                 return NULL;
402
403         lu_object_get(osp2lu_obj(obj));
404         INIT_LIST_HEAD(&ouc->ouc_list);
405         ouc->ouc_obj = obj;
406         ouc->ouc_data = data;
407         ouc->ouc_interpreter = interpreter;
408
409         return ouc;
410 }
411
412 /**
413  * Destroy the osp_update_callback.
414  *
415  * \param[in] env       pointer to the thread context
416  * \param[in] ouc       pointer to osp_update_callback
417  */
418 static void osp_update_callback_fini(const struct lu_env *env,
419                                      struct osp_update_callback *ouc)
420 {
421         LASSERT(list_empty(&ouc->ouc_list));
422
423         lu_object_put(env, osp2lu_obj(ouc->ouc_obj));
424         OBD_FREE_PTR(ouc);
425 }
426
427 /**
428  * Interpret the packaged OUT RPC results.
429  *
430  * For every packaged sub-request, call its registered interpreter function.
431  * Then destroy the sub-request.
432  *
433  * \param[in] env       pointer to the thread context
434  * \param[in] req       pointer to the RPC
435  * \param[in] arg       pointer to data used by the interpreter
436  * \param[in] rc        the RPC return value
437  *
438  * \retval              0 for success
439  * \retval              negative error number on failure
440  */
441 static int osp_update_interpret(const struct lu_env *env,
442                                 struct ptlrpc_request *req, void *arg, int rc)
443 {
444         struct object_update_reply      *reply  = NULL;
445         struct osp_update_args          *oaua   = arg;
446         struct osp_update_request       *our = oaua->oaua_update;
447         struct osp_thandle              *oth;
448         struct osp_update_callback      *ouc;
449         struct osp_update_callback      *next;
450         int                              count  = 0;
451         int                              index  = 0;
452         int                              rc1    = 0;
453
454         ENTRY;
455
456         if (our == NULL)
457                 RETURN(0);
458
459         oaua->oaua_update = NULL;
460         oth = our->our_th;
461         if (oaua->oaua_flow_control) {
462                 struct osp_device *osp;
463
464                 LASSERT(oth != NULL);
465                 osp = dt2osp_dev(oth->ot_super.th_dev);
466                 obd_put_request_slot(&osp->opd_obd->u.cli);
467         }
468
469         /* Unpack the results from the reply message. */
470         if (req->rq_repmsg != NULL) {
471                 reply = req_capsule_server_sized_get(&req->rq_pill,
472                                                      &RMF_OUT_UPDATE_REPLY,
473                                                      OUT_UPDATE_REPLY_SIZE);
474                 if (reply == NULL || reply->ourp_magic != UPDATE_REPLY_MAGIC)
475                         rc1 = -EPROTO;
476                 else
477                         count = reply->ourp_count;
478         } else {
479                 rc1 = rc;
480         }
481
482         list_for_each_entry_safe(ouc, next, &our->our_cb_items, ouc_list) {
483                 list_del_init(&ouc->ouc_list);
484
485                 /* The peer may only have handled some requests (indicated
486                  * by the 'count') in the packaged OUT RPC, we can only get
487                  * results for the handled part. */
488                 if (index < count && reply->ourp_lens[index] > 0) {
489                         struct object_update_result *result;
490
491                         result = object_update_result_get(reply, index, NULL);
492                         if (result == NULL)
493                                 rc1 = -EPROTO;
494                         else
495                                 rc1 = result->our_rc;
496                 } else {
497                         rc1 = rc;
498                         if (unlikely(rc1 == 0))
499                                 rc1 = -EINVAL;
500                 }
501
502                 if (ouc->ouc_interpreter != NULL)
503                         ouc->ouc_interpreter(env, reply, req, ouc->ouc_obj,
504                                              ouc->ouc_data, index, rc1);
505
506                 osp_update_callback_fini(env, ouc);
507                 index++;
508         }
509
510         if (oaua->oaua_count != NULL && atomic_dec_and_test(oaua->oaua_count))
511                 wake_up_all(oaua->oaua_waitq);
512
513         if (oth != NULL) {
514                 /* oth and osp_update_requests will be destoryed in
515                  * osp_thandle_put */
516                 osp_trans_stop_cb(oth, rc);
517                 osp_thandle_put(oth);
518         } else {
519                 osp_update_request_destroy(our);
520         }
521
522         RETURN(0);
523 }
524
525 /**
526  * Pack all the requests in the shared asynchronous idempotent request queue
527  * into a single OUT RPC that will be given to the background ptlrpcd daemon.
528  *
529  * \param[in] env       pointer to the thread context
530  * \param[in] osp       pointer to the OSP device
531  * \param[in] our       pointer to the shared queue
532  *
533  * \retval              0 for success
534  * \retval              negative error number on failure
535  */
536 int osp_unplug_async_request(const struct lu_env *env,
537                              struct osp_device *osp,
538                              struct osp_update_request *our)
539 {
540         struct osp_update_args  *args;
541         struct ptlrpc_request   *req = NULL;
542         int                      rc;
543
544         rc = osp_prep_update_req(env, osp->opd_obd->u.cli.cl_import,
545                                  our, &req);
546         if (rc != 0) {
547                 struct osp_update_callback *ouc;
548                 struct osp_update_callback *next;
549
550                 list_for_each_entry_safe(ouc, next,
551                                          &our->our_cb_items, ouc_list) {
552                         list_del_init(&ouc->ouc_list);
553                         if (ouc->ouc_interpreter != NULL)
554                                 ouc->ouc_interpreter(env, NULL, NULL,
555                                                      ouc->ouc_obj,
556                                                      ouc->ouc_data, 0, rc);
557                         osp_update_callback_fini(env, ouc);
558                 }
559                 osp_update_request_destroy(our);
560         } else {
561                 args = ptlrpc_req_async_args(req);
562                 args->oaua_update = our;
563                 args->oaua_count = NULL;
564                 args->oaua_waitq = NULL;
565                 args->oaua_flow_control = false;
566                 req->rq_interpret_reply = osp_update_interpret;
567                 ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
568         }
569
570         return rc;
571 }
572
573 /**
574  * Find or create (if NOT exist or purged) the shared asynchronous idempotent
575  * request queue - osp_device::opd_async_requests.
576  *
577  * If the osp_device::opd_async_requests is not NULL, then return it directly;
578  * otherwise create new osp_update_request and attach it to opd_async_requests.
579  *
580  * \param[in] osp       pointer to the OSP device
581  *
582  * \retval              pointer to the shared queue
583  * \retval              negative error number on failure
584  */
585 static struct osp_update_request *
586 osp_find_or_create_async_update_request(struct osp_device *osp)
587 {
588         struct osp_update_request *our = osp->opd_async_requests;
589
590         if (our != NULL)
591                 return our;
592
593         our = osp_update_request_create(&osp->opd_dt_dev);
594         if (IS_ERR(our))
595                 return our;
596
597         osp->opd_async_requests = our;
598
599         return our;
600 }
601
602 /**
603  * Insert an osp_update_callback into the osp_update_request.
604  *
605  * Insert an osp_update_callback to the osp_update_request. Usually each update
606  * in the osp_update_request will have one correspondent callback, and these
607  * callbacks will be called in rq_interpret_reply.
608  *
609  * \param[in] env               pointer to the thread context
610  * \param[in] obj               pointer to the operation target object
611  * \param[in] data              pointer to the data used by the interpreter
612  * \param[in] interpreter       pointer to the interpreter function
613  *
614  * \retval                      0 for success
615  * \retval                      negative error number on failure
616  */
617 int osp_insert_update_callback(const struct lu_env *env,
618                                struct osp_update_request *our,
619                                struct osp_object *obj, void *data,
620                                osp_update_interpreter_t interpreter)
621 {
622         struct osp_update_callback  *ouc;
623
624         ouc = osp_update_callback_init(obj, data, interpreter);
625         if (ouc == NULL)
626                 RETURN(-ENOMEM);
627
628         list_add_tail(&ouc->ouc_list, &our->our_cb_items);
629
630         return 0;
631 }
632
633 /**
634  * Insert an asynchronous idempotent request to the shared request queue that
635  * is attached to the osp_device.
636  *
637  * This function generates a new osp_async_request with the given parameters,
638  * then tries to insert the request into the osp_device-based shared request
639  * queue. If the queue is full, then triggers the packaged OUT RPC to purge
640  * the shared queue firstly, and then re-tries.
641  *
642  * NOTE: must hold the osp::opd_async_requests_mutex to serialize concurrent
643  *       osp_insert_async_request call from others.
644  *
645  * \param[in] env               pointer to the thread context
646  * \param[in] op                operation type, see 'enum update_type'
647  * \param[in] obj               pointer to the operation target
648  * \param[in] count             array size of the subsequent \a lens and \a bufs
649  * \param[in] lens              buffer length array for the subsequent \a bufs
650  * \param[in] bufs              the buffers to compose the request
651  * \param[in] data              pointer to the data used by the interpreter
652  * \param[in] interpreter       pointer to the interpreter function
653  *
654  * \retval                      0 for success
655  * \retval                      negative error number on failure
656  */
657 int osp_insert_async_request(const struct lu_env *env, enum update_type op,
658                              struct osp_object *obj, int count,
659                              __u16 *lens, const void **bufs, void *data,
660                              osp_update_interpreter_t interpreter)
661 {
662         struct osp_device               *osp;
663         struct osp_update_request       *our;
664         struct object_update            *object_update;
665         size_t                          max_update_size;
666         struct object_update_request    *ureq;
667         struct osp_update_request_sub   *ours;
668         int                             rc = 0;
669         ENTRY;
670
671         osp = lu2osp_dev(osp2lu_obj(obj)->lo_dev);
672         our = osp_find_or_create_async_update_request(osp);
673         if (IS_ERR(our))
674                 RETURN(PTR_ERR(our));
675
676 again:
677         ours = osp_current_object_update_request(our);
678
679         ureq = ours->ours_req;
680         max_update_size = ours->ours_req_size -
681                           object_update_request_size(ureq);
682
683         object_update = update_buffer_get_update(ureq, ureq->ourq_count);
684         rc = out_update_pack(env, object_update, &max_update_size, op,
685                              lu_object_fid(osp2lu_obj(obj)), count, lens, bufs);
686         /* The queue is full. */
687         if (rc == -E2BIG) {
688                 osp->opd_async_requests = NULL;
689                 mutex_unlock(&osp->opd_async_requests_mutex);
690
691                 rc = osp_unplug_async_request(env, osp, our);
692                 mutex_lock(&osp->opd_async_requests_mutex);
693                 if (rc != 0)
694                         RETURN(rc);
695
696                 our = osp_find_or_create_async_update_request(osp);
697                 if (IS_ERR(our))
698                         RETURN(PTR_ERR(our));
699
700                 goto again;
701         } else {
702                 if (rc < 0)
703                         RETURN(rc);
704
705                 ureq->ourq_count++;
706         }
707
708         rc = osp_insert_update_callback(env, our, obj, data, interpreter);
709
710         RETURN(rc);
711 }
712
713 int osp_trans_update_request_create(struct thandle *th)
714 {
715         struct osp_thandle              *oth = thandle_to_osp_thandle(th);
716         struct osp_update_request       *our;
717
718         if (oth->ot_our != NULL)
719                 return 0;
720
721         our = osp_update_request_create(th->th_dev);
722         if (IS_ERR(our)) {
723                 th->th_result = PTR_ERR(our);
724                 return PTR_ERR(our);
725         }
726
727         oth->ot_our = our;
728         our->our_th = oth;
729
730         if (oth->ot_super.th_sync)
731                 oth->ot_our->our_flags |= UPDATE_FL_SYNC;
732
733         return 0;
734 }
735
736 void osp_thandle_destroy(struct osp_thandle *oth)
737 {
738         LASSERT(oth->ot_magic == OSP_THANDLE_MAGIC);
739         LASSERT(list_empty(&oth->ot_commit_dcb_list));
740         LASSERT(list_empty(&oth->ot_stop_dcb_list));
741         if (oth->ot_our != NULL)
742                 osp_update_request_destroy(oth->ot_our);
743         OBD_FREE_PTR(oth);
744 }
745
746 /**
747  * The OSP layer dt_device_operations::dt_trans_create() interface
748  * to create a transaction.
749  *
750  * There are two kinds of transactions that will involve OSP:
751  *
752  * 1) If the transaction only contains the updates on remote server
753  *    (MDT or OST), such as re-generating the lost OST-object for
754  *    LFSCK, then it is a remote transaction. For remote transaction,
755  *    the upper layer caller (such as the LFSCK engine) will call the
756  *    dt_trans_create() (with the OSP dt_device as the parameter),
757  *    then the call will be directed to the osp_trans_create() that
758  *    creates the transaction handler and returns it to the caller.
759  *
760  * 2) If the transcation contains both local and remote updates,
761  *    such as cross MDTs create under DNE mode, then the upper layer
762  *    caller will not trigger osp_trans_create(). Instead, it will
763  *    call dt_trans_create() on other dt_device, such as LOD that
764  *    will generate the transaction handler. Such handler will be
765  *    used by the whole transaction in subsequent sub-operations.
766  *
767  * \param[in] env       pointer to the thread context
768  * \param[in] d         pointer to the OSP dt_device
769  *
770  * \retval              pointer to the transaction handler
771  * \retval              negative error number on failure
772  */
773 struct thandle *osp_trans_create(const struct lu_env *env, struct dt_device *d)
774 {
775         struct osp_thandle              *oth;
776         struct thandle                  *th = NULL;
777         ENTRY;
778
779         OBD_ALLOC_PTR(oth);
780         if (unlikely(oth == NULL))
781                 RETURN(ERR_PTR(-ENOMEM));
782
783         oth->ot_magic = OSP_THANDLE_MAGIC;
784         th = &oth->ot_super;
785         th->th_dev = d;
786         th->th_tags = LCT_TX_HANDLE;
787
788         atomic_set(&oth->ot_refcount, 1);
789         INIT_LIST_HEAD(&oth->ot_commit_dcb_list);
790         INIT_LIST_HEAD(&oth->ot_stop_dcb_list);
791
792         RETURN(th);
793 }
794
795 /**
796  * Add commit callback to transaction.
797  *
798  * Add commit callback to the osp thandle, which will be called
799  * when the thandle is committed remotely.
800  *
801  * \param[in] th        the thandle
802  * \param[in] dcb       commit callback structure
803  *
804  * \retval              only return 0 for now.
805  */
806 int osp_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
807 {
808         struct osp_thandle *oth = thandle_to_osp_thandle(th);
809
810         LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
811         LASSERT(&dcb->dcb_func != NULL);
812         if (dcb->dcb_flags & DCB_TRANS_STOP)
813                 list_add(&dcb->dcb_linkage, &oth->ot_stop_dcb_list);
814         else
815                 list_add(&dcb->dcb_linkage, &oth->ot_commit_dcb_list);
816         return 0;
817 }
818
819 static void osp_trans_commit_cb(struct osp_thandle *oth, int result)
820 {
821         struct dt_txn_commit_cb *dcb;
822         struct dt_txn_commit_cb *tmp;
823
824         LASSERT(atomic_read(&oth->ot_refcount) > 0);
825         /* call per-transaction callbacks if any */
826         list_for_each_entry_safe(dcb, tmp, &oth->ot_commit_dcb_list,
827                                  dcb_linkage) {
828                 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
829                          "commit callback entry: magic=%x name='%s'\n",
830                          dcb->dcb_magic, dcb->dcb_name);
831                 list_del_init(&dcb->dcb_linkage);
832                 dcb->dcb_func(NULL, &oth->ot_super, dcb, result);
833         }
834 }
835
836 static void osp_request_commit_cb(struct ptlrpc_request *req)
837 {
838         struct thandle          *th = req->rq_cb_data;
839         struct osp_thandle      *oth;
840         __u64                   last_committed_transno = 0;
841         int                     result = req->rq_status;
842         ENTRY;
843
844         if (th == NULL)
845                 RETURN_EXIT;
846
847         oth = thandle_to_osp_thandle(th);
848         if (lustre_msg_get_last_committed(req->rq_repmsg))
849                 last_committed_transno =
850                         lustre_msg_get_last_committed(req->rq_repmsg);
851
852         if (last_committed_transno <
853                 req->rq_import->imp_peer_committed_transno)
854                 last_committed_transno =
855                         req->rq_import->imp_peer_committed_transno;
856
857         CDEBUG(D_HA, "trans no "LPU64" committed transno "LPU64"\n",
858                req->rq_transno, last_committed_transno);
859
860         /* If the transaction is not really committed, mark result = 1 */
861         if (req->rq_transno != 0 &&
862             (req->rq_transno > last_committed_transno) && result == 0)
863                 result = 1;
864
865         osp_trans_commit_cb(oth, result);
866         req->rq_committed = 1;
867         osp_thandle_put(oth);
868         EXIT;
869 }
870
871 /**
872  * callback of osp transaction
873  *
874  * Call all of callbacks for this osp thandle. This will only be
875  * called in error handler path. In the normal processing path,
876  * these callback will be called in osp_request_commit_cb() and
877  * osp_update_interpret().
878  *
879  * \param [in] env      execution environment
880  * \param [in] oth      osp thandle
881  * \param [in] rc       result of the osp thandle
882  */
883 void osp_trans_callback(const struct lu_env *env,
884                         struct osp_thandle *oth, int rc)
885 {
886         struct osp_update_callback *ouc;
887         struct osp_update_callback *next;
888
889         if (oth->ot_our != NULL) {
890                 list_for_each_entry_safe(ouc, next,
891                                          &oth->ot_our->our_cb_items, ouc_list) {
892                         list_del_init(&ouc->ouc_list);
893                         if (ouc->ouc_interpreter != NULL)
894                                 ouc->ouc_interpreter(env, NULL, NULL,
895                                                      ouc->ouc_obj,
896                                                      ouc->ouc_data, 0, rc);
897                         osp_update_callback_fini(env, ouc);
898                 }
899         }
900         osp_trans_stop_cb(oth, rc);
901         osp_trans_commit_cb(oth, rc);
902 }
903
904 /**
905  * Send the request for remote updates.
906  *
907  * Send updates to the remote MDT. Prepare the request by osp_update_req
908  * and send them to remote MDT, for sync request, it will wait
909  * until the reply return, otherwise hand it to ptlrpcd.
910  *
911  * Please refer to osp_trans_create() for transaction type.
912  *
913  * \param[in] env               pointer to the thread context
914  * \param[in] osp               pointer to the OSP device
915  * \param[in] our               pointer to the osp_update_request
916  *
917  * \retval                      0 for success
918  * \retval                      negative error number on failure
919  */
920 static int osp_send_update_req(const struct lu_env *env,
921                                struct osp_device *osp,
922                                struct osp_update_request *our)
923 {
924         struct osp_update_args  *args;
925         struct ptlrpc_request   *req;
926         struct lu_device *top_device;
927         struct osp_thandle      *oth = our->our_th;
928         int     rc = 0;
929         ENTRY;
930
931         LASSERT(oth != NULL);
932         LASSERT(our->our_req_sent == 0);
933         rc = osp_prep_update_req(env, osp->opd_obd->u.cli.cl_import,
934                                  our, &req);
935         if (rc != 0) {
936                 osp_trans_callback(env, oth, rc);
937                 RETURN(rc);
938         }
939
940         args = ptlrpc_req_async_args(req);
941         args->oaua_update = our;
942         osp_thandle_get(oth); /* hold for update interpret */
943         req->rq_interpret_reply = osp_update_interpret;
944         if (!oth->ot_super.th_wait_submit && !oth->ot_super.th_sync) {
945                 if (!osp->opd_imp_active || !osp->opd_imp_connected) {
946                         osp_trans_callback(env, oth, rc);
947                         osp_thandle_put(oth);
948                         GOTO(out, rc = -ENOTCONN);
949                 }
950
951                 rc = obd_get_request_slot(&osp->opd_obd->u.cli);
952                 if (rc != 0) {
953                         osp_trans_callback(env, oth, rc);
954                         osp_thandle_put(oth);
955                         GOTO(out, rc = -ENOTCONN);
956                 }
957                 args->oaua_flow_control = true;
958
959                 if (!osp->opd_connect_mdt) {
960                         down_read(&osp->opd_async_updates_rwsem);
961                         args->oaua_count = &osp->opd_async_updates_count;
962                         args->oaua_waitq = &osp->opd_syn_barrier_waitq;
963                         up_read(&osp->opd_async_updates_rwsem);
964                         atomic_inc(args->oaua_count);
965                 }
966
967                 ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
968                 req = NULL;
969         } else {
970                 osp_thandle_get(oth); /* hold for commit callback */
971                 req->rq_commit_cb = osp_request_commit_cb;
972                 req->rq_cb_data = &oth->ot_super;
973                 args->oaua_flow_control = false;
974
975                 /* If the transaction is created during MDT recoverying
976                  * process, it means this is an recovery update, we need
977                  * to let OSP send it anyway without checking recoverying
978                  * status, in case the other target is being recoveried
979                  * at the same time, and if we wait here for the import
980                  * to be recoveryed, it might cause deadlock */
981                 top_device = osp->opd_dt_dev.dd_lu_dev.ld_site->ls_top_dev;
982                 if (top_device->ld_obd->obd_recovering)
983                         req->rq_allow_replay = 1;
984
985                 osp_get_rpc_lock(osp);
986                 rc = ptlrpc_queue_wait(req);
987                 osp_put_rpc_lock(osp);
988                 if ((rc == -ENOMEM && req->rq_set == NULL) ||
989                     (req->rq_transno == 0 && !req->rq_committed)) {
990                         if (args->oaua_update != NULL) {
991                                 /* If osp_update_interpret is not being called,
992                                  * release the osp_thandle */
993                                 args->oaua_update = NULL;
994                                 osp_thandle_put(oth);
995                         }
996
997                         req->rq_cb_data = NULL;
998                         rc = rc == 0 ? req->rq_status : rc;
999                         osp_trans_callback(env, oth, rc);
1000                         osp_thandle_put(oth);
1001                         GOTO(out, rc);
1002                 }
1003         }
1004 out:
1005         if (req != NULL)
1006                 ptlrpc_req_finished(req);
1007
1008         RETURN(rc);
1009 }
1010
1011 /**
1012  * Get local thandle for osp_thandle
1013  *
1014  * Get the local OSD thandle from the OSP thandle. Currently, there
1015  * are a few OSP API (osp_object_create() and osp_sync_add()) needs
1016  * to update the object on local OSD device.
1017  *
1018  * If the osp_thandle comes from normal stack (MDD->LOD->OSP), then
1019  * we will get local thandle by thandle_get_sub_by_dt.
1020  *
1021  * If the osp_thandle is remote thandle (th_top == NULL, only used
1022  * by LFSCK), then it will create a local thandle, and stop it in
1023  * osp_trans_stop(). And this only happens on OSP for OST.
1024  *
1025  * These are temporary solution, once OSP accessing OSD object is
1026  * being fixed properly, this function should be removed. XXX
1027  *
1028  * \param[in] env               pointer to the thread context
1029  * \param[in] th                pointer to the transaction handler
1030  * \param[in] dt                pointer to the OSP device
1031  *
1032  * \retval                      pointer to the local thandle
1033  * \retval                      ERR_PTR(errno) if it fails.
1034  **/
1035 struct thandle *osp_get_storage_thandle(const struct lu_env *env,
1036                                         struct thandle *th,
1037                                         struct osp_device *osp)
1038 {
1039         struct osp_thandle      *oth;
1040         struct thandle          *local_th;
1041
1042         if (th->th_top != NULL)
1043                 return thandle_get_sub_by_dt(env, th->th_top,
1044                                              osp->opd_storage);
1045
1046         LASSERT(!osp->opd_connect_mdt);
1047         oth = thandle_to_osp_thandle(th);
1048         if (oth->ot_storage_th != NULL)
1049                 return oth->ot_storage_th;
1050
1051         local_th = dt_trans_create(env, osp->opd_storage);
1052         if (IS_ERR(local_th))
1053                 return local_th;
1054
1055         oth->ot_storage_th = local_th;
1056
1057         return local_th;
1058 }
1059
1060 /**
1061  * Set version for the transaction
1062  *
1063  * Set the version for the transaction, then the osp RPC will be
1064  * sent in the order of version, i.e. the transaction with lower
1065  * version will be sent first.
1066  *
1067  * \param [in] oth      osp thandle to be set version.
1068  *
1069  * \retval              0 if set version succeeds
1070  *                      negative errno if set version fails.
1071  */
1072 int osp_check_and_set_rpc_version(struct osp_thandle *oth)
1073 {
1074         struct osp_device *osp = dt2osp_dev(oth->ot_super.th_dev);
1075         struct osp_updates *ou = osp->opd_update;
1076
1077         if (ou == NULL)
1078                 return -EIO;
1079
1080         if (oth->ot_version != 0)
1081                 return 0;
1082
1083         spin_lock(&ou->ou_lock);
1084         oth->ot_version = ou->ou_version++;
1085         spin_unlock(&ou->ou_lock);
1086
1087         CDEBUG(D_INFO, "%s: version "LPU64" oth:version %p:"LPU64"\n",
1088                osp->opd_obd->obd_name, ou->ou_version, oth, oth->ot_version);
1089
1090         return 0;
1091 }
1092
1093 /**
1094  * Get next OSP update request in the sending list
1095  * Get next OSP update request in the sending list by version number, next
1096  * request will be
1097  * 1. transaction which does not have a version number.
1098  * 2. transaction whose version == opd_rpc_version.
1099  *
1100  * \param [in] ou       osp update structure.
1101  * \param [out] ourp    the pointer holding the next update request.
1102  *
1103  * \retval              true if getting the next transaction.
1104  * \retval              false if not getting the next transaction.
1105  */
1106 static bool
1107 osp_get_next_request(struct osp_updates *ou, struct osp_update_request **ourp)
1108 {
1109         struct osp_update_request *our;
1110         struct osp_update_request *tmp;
1111         bool                    got_req = false;
1112
1113         spin_lock(&ou->ou_lock);
1114         list_for_each_entry_safe(our, tmp, &ou->ou_list, our_list) {
1115                 LASSERT(our->our_th != NULL);
1116                 CDEBUG(D_INFO, "our %p version "LPU64" rpc_version "LPU64"\n",
1117                        our, our->our_th->ot_version, ou->ou_rpc_version);
1118                 if (our->our_th->ot_version == 0) {
1119                         list_del_init(&our->our_list);
1120                         *ourp = our;
1121                         got_req = true;
1122                         break;
1123                 }
1124
1125                 /* Find next osp_update_request in the list */
1126                 if (our->our_th->ot_version == ou->ou_rpc_version) {
1127                         list_del_init(&our->our_list);
1128                         *ourp = our;
1129                         got_req = true;
1130                         break;
1131                 }
1132         }
1133         spin_unlock(&ou->ou_lock);
1134
1135         return got_req;
1136 }
1137
1138 static void osp_update_rpc_version(struct osp_updates *ou,
1139                                    struct osp_thandle *oth)
1140 {
1141         if (oth->ot_version == 0)
1142                 return;
1143
1144         LASSERT(oth->ot_version == ou->ou_rpc_version);
1145         spin_lock(&ou->ou_lock);
1146         ou->ou_rpc_version++;
1147         spin_unlock(&ou->ou_lock);
1148 }
1149
1150 /**
1151  * Sending update thread
1152  *
1153  * Create thread to send update request to other MDTs, this thread will pull
1154  * out update request from the list in OSP by version number, i.e. it will
1155  * make sure the update request with lower version number will be sent first.
1156  *
1157  * \param[in] arg       hold the OSP device.
1158  *
1159  * \retval              0 if the thread is created successfully.
1160  * \retal               negative error if the thread is not created
1161  *                      successfully.
1162  */
1163 int osp_send_update_thread(void *arg)
1164 {
1165         struct lu_env           env;
1166         struct osp_device       *osp = arg;
1167         struct l_wait_info       lwi = { 0 };
1168         struct osp_updates      *ou = osp->opd_update;
1169         struct ptlrpc_thread    *thread = &osp->opd_update_thread;
1170         struct osp_update_request *our = NULL;
1171         int                     rc;
1172         ENTRY;
1173
1174         LASSERT(ou != NULL);
1175         rc = lu_env_init(&env, osp->opd_dt_dev.dd_lu_dev.ld_type->ldt_ctx_tags);
1176         if (rc < 0) {
1177                 CERROR("%s: init env error: rc = %d\n", osp->opd_obd->obd_name,
1178                        rc);
1179                 RETURN(rc);
1180         }
1181
1182         thread->t_flags = SVC_RUNNING;
1183         wake_up(&thread->t_ctl_waitq);
1184         while (1) {
1185                 our = NULL;
1186                 l_wait_event(ou->ou_waitq,
1187                              !osp_send_update_thread_running(osp) ||
1188                              osp_get_next_request(ou, &our),
1189                              &lwi);
1190
1191                 if (!osp_send_update_thread_running(osp)) {
1192                         if (our != NULL && our->our_th != NULL) {
1193                                 osp_trans_callback(&env, our->our_th, -EINTR);
1194                                 osp_thandle_put(our->our_th);
1195                         }
1196                         break;
1197                 }
1198
1199                 if (our->our_req_sent == 0) {
1200                         if (our->our_th != NULL &&
1201                             our->our_th->ot_super.th_result != 0)
1202                                 osp_trans_callback(&env, our->our_th,
1203                                         our->our_th->ot_super.th_result);
1204                         else
1205                                 rc = osp_send_update_req(&env, osp, our);
1206                 }
1207
1208                 if (our->our_th != NULL) {
1209                         /* Update the rpc version */
1210                         osp_update_rpc_version(ou, our->our_th);
1211                         /* Balanced for thandle_get in osp_trans_trigger() */
1212                         osp_thandle_put(our->our_th);
1213                 }
1214         }
1215
1216         thread->t_flags = SVC_STOPPED;
1217         lu_env_fini(&env);
1218         wake_up(&thread->t_ctl_waitq);
1219
1220         RETURN(0);
1221 }
1222
1223 /**
1224  * Trigger the request for remote updates.
1225  *
1226  * Add the request to the sending list, and wake up osp update
1227  * sending thread.
1228  *
1229  * \param[in] env               pointer to the thread context
1230  * \param[in] osp               pointer to the OSP device
1231  * \param[in] oth               pointer to the transaction handler
1232  *
1233  */
1234 static void osp_trans_trigger(const struct lu_env *env,
1235                              struct osp_device *osp,
1236                              struct osp_thandle *oth)
1237 {
1238
1239         CDEBUG(D_INFO, "%s: add oth %p with version "LPU64"\n",
1240                osp->opd_obd->obd_name, oth, oth->ot_version);
1241
1242         LASSERT(oth->ot_magic == OSP_THANDLE_MAGIC);
1243         osp_thandle_get(oth);
1244         LASSERT(oth->ot_our != NULL);
1245         spin_lock(&osp->opd_update->ou_lock);
1246         list_add_tail(&oth->ot_our->our_list,
1247                       &osp->opd_update->ou_list);
1248         spin_unlock(&osp->opd_update->ou_lock);
1249
1250         wake_up(&osp->opd_update->ou_waitq);
1251 }
1252
1253 /**
1254  * The OSP layer dt_device_operations::dt_trans_start() interface
1255  * to start the transaction.
1256  *
1257  * If the transaction is a remote transaction, then related remote
1258  * updates will be triggered in the osp_trans_stop().
1259  * Please refer to osp_trans_create() for transaction type.
1260  *
1261  * \param[in] env               pointer to the thread context
1262  * \param[in] dt                pointer to the OSP dt_device
1263  * \param[in] th                pointer to the transaction handler
1264  *
1265  * \retval                      0 for success
1266  * \retval                      negative error number on failure
1267  */
1268 int osp_trans_start(const struct lu_env *env, struct dt_device *dt,
1269                     struct thandle *th)
1270 {
1271         struct osp_thandle      *oth = thandle_to_osp_thandle(th);
1272
1273         /* For remote thandle, if there are local thandle, start it here*/
1274         if (is_only_remote_trans(th) && oth->ot_storage_th != NULL)
1275                 return dt_trans_start(env, oth->ot_storage_th->th_dev,
1276                                       oth->ot_storage_th);
1277         return 0;
1278 }
1279
1280 /**
1281  * The OSP layer dt_device_operations::dt_trans_stop() interface
1282  * to stop the transaction.
1283  *
1284  * If the transaction is a remote transaction, related remote
1285  * updates will be triggered here via osp_trans_trigger().
1286  *
1287  * For synchronous mode update or any failed update, the request
1288  * will be destroyed explicitly when the osp_trans_stop().
1289  *
1290  * Please refer to osp_trans_create() for transaction type.
1291  *
1292  * \param[in] env               pointer to the thread context
1293  * \param[in] dt                pointer to the OSP dt_device
1294  * \param[in] th                pointer to the transaction handler
1295  *
1296  * \retval                      0 for success
1297  * \retval                      negative error number on failure
1298  */
1299 int osp_trans_stop(const struct lu_env *env, struct dt_device *dt,
1300                    struct thandle *th)
1301 {
1302         struct osp_thandle       *oth = thandle_to_osp_thandle(th);
1303         struct osp_update_request *our = oth->ot_our;
1304         struct osp_device        *osp = dt2osp_dev(dt);
1305         int                      rc = 0;
1306         ENTRY;
1307
1308         /* For remote transaction, if there is local storage thandle,
1309          * stop it first */
1310         if (oth->ot_storage_th != NULL && th->th_top == NULL) {
1311                 dt_trans_stop(env, oth->ot_storage_th->th_dev,
1312                               oth->ot_storage_th);
1313                 oth->ot_storage_th = NULL;
1314         }
1315
1316         if (our == NULL || list_empty(&our->our_req_list)) {
1317                 osp_trans_callback(env, oth, th->th_result);
1318                 GOTO(out, rc = th->th_result);
1319         }
1320
1321         if (!osp->opd_connect_mdt) {
1322                 rc = osp_send_update_req(env, osp, oth->ot_our);
1323                 GOTO(out, rc);
1324         }
1325
1326         if (osp->opd_update == NULL ||
1327             !osp_send_update_thread_running(osp)) {
1328                 osp_trans_callback(env, oth, -EIO);
1329                 GOTO(out, rc = -EIO);
1330         }
1331
1332         if (th->th_sync) {
1333                 /* if th_sync is set, then it needs to be sent
1334                  * right away. Note: even thought the RPC has been
1335                  * sent, it still needs to be added to the sending
1336                  * list (see osp_trans_trigger()), so ou_rpc_version
1337                  * can be updated correctly. */
1338                 rc = osp_send_update_req(env, osp, our);
1339                 our->our_req_sent = 1;
1340         }
1341
1342         osp_trans_trigger(env, osp, oth);
1343 out:
1344         osp_thandle_put(oth);
1345
1346         RETURN(rc);
1347 }