4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/osp/osp_sync.c
38 * Lustre OST Proxy Device
40 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
41 * Author: Mikhail Pershin <mike.pershin@intel.com>
42 * Author: Di Wang <di.wang@intel.com>
45 #define DEBUG_SUBSYSTEM S_MDS
47 #include <linux/kthread.h>
49 #include <lustre_obdo.h>
51 #include "osp_internal.h"
54 * there are two specific states to take care about:
56 * = import is disconnected =
58 * = import is inactive =
59 * in this case osp_declare_object_create() returns an error
65 * Check whether statfs data is expired
67 * OSP device caches statfs data for the target, the function checks
68 * whether the data is expired or not.
70 * \param[in] d OSP device
72 * \retval 0 - not expired, 1 - expired
74 static inline int osp_statfs_need_update(struct osp_device *d)
76 return !cfs_time_before(cfs_time_current(),
77 d->opd_statfs_fresh_till);
81 * OSP tries to maintain pool of available objects so that calls to create
82 * objects don't block most of time
84 * each time OSP gets connected to OST, we should start from precreation cleanup
86 static inline bool osp_precreate_running(struct osp_device *d)
88 return !!(d->opd_pre_thread.t_flags & SVC_RUNNING);
91 static inline bool osp_precreate_stopped(struct osp_device *d)
93 return !!(d->opd_pre_thread.t_flags & SVC_STOPPED);
96 static void osp_statfs_timer_cb(unsigned long _d)
98 struct osp_device *d = (struct osp_device *) _d;
101 if (d->opd_pre != NULL && osp_precreate_running(d))
102 wake_up(&d->opd_pre_waitq);
106 * RPC interpret callback for OST_STATFS RPC
108 * An interpretation callback called by ptlrpc for OST_STATFS RPC when it is
109 * replied by the target. It's used to maintain statfs cache for the target.
110 * The function fills data from the reply if successful and schedules another
113 * \param[in] env LU environment provided by the caller
114 * \param[in] req RPC replied
115 * \param[in] aa callback data
116 * \param[in] rc RPC result
118 * \retval 0 on success
119 * \retval negative negated errno on error
121 static int osp_statfs_interpret(const struct lu_env *env,
122 struct ptlrpc_request *req,
123 union ptlrpc_async_args *aa, int rc)
125 struct obd_import *imp = req->rq_import;
126 struct obd_statfs *msfs;
127 struct osp_device *d;
131 aa = ptlrpc_req_async_args(req);
132 d = aa->pointer_arg[0];
138 msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
140 GOTO(out, rc = -EPROTO);
142 d->opd_statfs = *msfs;
144 osp_pre_update_status(d, rc);
146 /* schedule next update */
147 d->opd_statfs_fresh_till = cfs_time_shift(d->opd_statfs_maxage);
148 cfs_timer_arm(&d->opd_statfs_timer, d->opd_statfs_fresh_till);
149 d->opd_statfs_update_in_progress = 0;
151 CDEBUG(D_CACHE, "updated statfs %p\n", d);
155 /* couldn't update statfs, try again as soon as possible */
156 if (d->opd_pre != NULL && osp_precreate_running(d))
157 wake_up(&d->opd_pre_waitq);
159 if (req->rq_import_generation == imp->imp_generation)
160 CDEBUG(D_CACHE, "%s: couldn't update statfs: rc = %d\n",
161 d->opd_obd->obd_name, rc);
166 * Send OST_STATFS RPC
168 * Sends OST_STATFS RPC to refresh cached statfs data for the target.
169 * Also disables scheduled updates as times OSP may need to refresh
170 * statfs data before expiration. The function doesn't block, instead
171 * an interpretation callback osp_statfs_interpret() is used.
173 * \param[in] d OSP device
175 static int osp_statfs_update(struct osp_device *d)
177 struct ptlrpc_request *req;
178 struct obd_import *imp;
179 union ptlrpc_async_args *aa;
184 CDEBUG(D_CACHE, "going to update statfs\n");
186 imp = d->opd_obd->u.cli.cl_import;
189 req = ptlrpc_request_alloc(imp, &RQF_OST_STATFS);
193 rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_STATFS);
195 ptlrpc_request_free(req);
198 ptlrpc_request_set_replen(req);
199 req->rq_request_portal = OST_CREATE_PORTAL;
200 ptlrpc_at_set_req_timeout(req);
202 req->rq_interpret_reply = (ptlrpc_interpterer_t)osp_statfs_interpret;
203 aa = ptlrpc_req_async_args(req);
204 aa->pointer_arg[0] = d;
207 * no updates till reply
209 cfs_timer_disarm(&d->opd_statfs_timer);
210 d->opd_statfs_fresh_till = cfs_time_shift(obd_timeout * 1000);
211 d->opd_statfs_update_in_progress = 1;
213 ptlrpcd_add_req(req);
219 * Schedule an immediate update for statfs data
221 * If cached statfs data claim no free space, but OSP has got a request to
222 * destroy an object (so release some space probably), then we may need to
223 * refresh cached statfs data sooner than planned. The function checks there
224 * is no statfs update going and schedules immediate update if so.
225 * XXX: there might be a case where removed object(s) do not add free space (empty
226 * object). If the number of such deletions is high, then we can start to update
227 * statfs too often causing a RPC storm. some throttling is needed...
229 * \param[in] d OSP device where statfs data needs to be refreshed
231 void osp_statfs_need_now(struct osp_device *d)
233 if (!d->opd_statfs_update_in_progress) {
235 * if current status is -ENOSPC (lack of free space on OST)
236 * then we should poll OST immediately once object destroy
239 d->opd_statfs_fresh_till = cfs_time_shift(-1);
240 cfs_timer_disarm(&d->opd_statfs_timer);
241 wake_up(&d->opd_pre_waitq);
246 * Return number of precreated objects
248 * A simple helper to calculate the number of precreated objects on the device.
250 * \param[in] env LU environment provided by the caller
251 * \param[in] osp OSP device
253 * \retval the number of the precreated objects
255 static inline int osp_objs_precreated(const struct lu_env *env,
256 struct osp_device *osp)
258 return osp_fid_diff(&osp->opd_pre_last_created_fid,
259 &osp->opd_pre_used_fid);
263 * Check pool of precreated objects is nearly empty
265 * We should not wait till the pool of the precreated objects is exhausted,
266 * because then there will be a long period of OSP being unavailable for the
267 * new creations due to lenghty precreate RPC. Instead we ask for another
268 * precreation ahead and hopefully have it ready before the current pool is
269 * empty. Notice this function relies on an external locking.
271 * \param[in] env LU environment provided by the caller
272 * \param[in] d OSP device
274 * \retval 0 - current pool is good enough, 1 - time to precreate
276 static inline int osp_precreate_near_empty_nolock(const struct lu_env *env,
277 struct osp_device *d)
279 int window = osp_objs_precreated(env, d);
281 /* don't consider new precreation till OST is healty and
283 return ((window - d->opd_pre_reserved < d->opd_pre_create_count / 2) &&
284 (d->opd_pre_status == 0));
288 * Check pool of precreated objects
290 * This is protected version of osp_precreate_near_empty_nolock(), check that
293 * \param[in] env LU environment provided by the caller
294 * \param[in] d OSP device
296 * \retval 0 - current pool is good enough, 1 - time to precreate
298 static inline int osp_precreate_near_empty(const struct lu_env *env,
299 struct osp_device *d)
303 /* XXX: do we really need locking here? */
304 spin_lock(&d->opd_pre_lock);
305 rc = osp_precreate_near_empty_nolock(env, d);
306 spin_unlock(&d->opd_pre_lock);
311 * Check given sequence is empty
313 * Returns a binary result whether the given sequence has some IDs left
314 * or not. Find the details in osp_fid_end_seq(). This is a lock protected
315 * version of that function.
317 * \param[in] env LU environment provided by the caller
318 * \param[in] osp OSP device
320 * \retval 0 - current sequence has no IDs, 1 - otherwise
322 static inline int osp_create_end_seq(const struct lu_env *env,
323 struct osp_device *osp)
325 struct lu_fid *fid = &osp->opd_pre_used_fid;
328 spin_lock(&osp->opd_pre_lock);
329 rc = osp_fid_end_seq(env, fid);
330 spin_unlock(&osp->opd_pre_lock);
335 * Write FID into into last_oid/last_seq file
337 * The function stores the sequence and the in-sequence id into two dedicated
338 * files. The sync argument can be used to request synchronous commit, so the
339 * function won't return until the updates are committed.
341 * \param[in] env LU environment provided by the caller
342 * \param[in] osp OSP device
343 * \param[in] fid fid where sequence/id is taken
344 * \param[in] sync update mode: 0 - asynchronously, 1 - synchronously
346 * \retval 0 on success
347 * \retval negative negated errno on error
349 int osp_write_last_oid_seq_files(struct lu_env *env, struct osp_device *osp,
350 struct lu_fid *fid, int sync)
352 struct osp_thread_info *oti = osp_env_info(env);
353 struct lu_buf *lb_oid = &oti->osi_lb;
354 struct lu_buf *lb_oseq = &oti->osi_lb2;
361 /* Note: through f_oid is only 32 bits, it will also write 64 bits
362 * for oid to keep compatibility with the previous version. */
363 lb_oid->lb_buf = &fid->f_oid;
364 lb_oid->lb_len = sizeof(u64);
365 oid_off = sizeof(u64) * osp->opd_index;
367 lb_oseq->lb_buf = &fid->f_seq;
368 lb_oseq->lb_len = sizeof(u64);
369 oseq_off = sizeof(u64) * osp->opd_index;
371 th = dt_trans_create(env, osp->opd_storage);
376 rc = dt_declare_record_write(env, osp->opd_last_used_oid_file,
377 lb_oid, oid_off, th);
381 rc = dt_declare_record_write(env, osp->opd_last_used_seq_file,
382 lb_oseq, oseq_off, th);
386 rc = dt_trans_start_local(env, osp->opd_storage, th);
390 rc = dt_record_write(env, osp->opd_last_used_oid_file, lb_oid,
393 CERROR("%s: can not write to last seq file: rc = %d\n",
394 osp->opd_obd->obd_name, rc);
397 rc = dt_record_write(env, osp->opd_last_used_seq_file, lb_oseq,
400 CERROR("%s: can not write to last seq file: rc = %d\n",
401 osp->opd_obd->obd_name, rc);
405 dt_trans_stop(env, osp->opd_storage, th);
410 * Switch to another sequence
412 * When a current sequence has no available IDs left, OSP has to switch to
413 * another new sequence. OSP requests it using the regular FLDB protocol
414 * and stores synchronously before that is used in precreated. This is needed
415 * to basically have the sequences referenced (not orphaned), otherwise it's
416 * possible that OST has some objects precreated and the clients have data
417 * written to it, but after MDT failover nobody refers those objects and OSP
418 * has no idea that the sequence need cleanup to be done.
419 * While this is very expensive operation, it's supposed to happen very very
420 * infrequently because sequence has 2^32 or 2^48 objects (depending on type)
422 * \param[in] env LU environment provided by the caller
423 * \param[in] osp OSP device
425 * \retval 0 on success
426 * \retval negative negated errno on error
428 static int osp_precreate_rollover_new_seq(struct lu_env *env,
429 struct osp_device *osp)
431 struct lu_fid *fid = &osp_env_info(env)->osi_fid;
432 struct lu_fid *last_fid = &osp->opd_last_used_fid;
436 rc = seq_client_get_seq(env, osp->opd_obd->u.cli.cl_seq, &fid->f_seq);
438 CERROR("%s: alloc fid error: rc = %d\n",
439 osp->opd_obd->obd_name, rc);
445 LASSERTF(fid_seq(fid) != fid_seq(last_fid),
446 "fid "DFID", last_fid "DFID"\n", PFID(fid),
449 rc = osp_write_last_oid_seq_files(env, osp, fid, 1);
451 CERROR("%s: Can not update oid/seq file: rc = %d\n",
452 osp->opd_obd->obd_name, rc);
456 LCONSOLE_INFO("%s: update sequence from "LPX64" to "LPX64"\n",
457 osp->opd_obd->obd_name, fid_seq(last_fid),
459 /* Update last_xxx to the new seq */
460 spin_lock(&osp->opd_pre_lock);
461 osp->opd_last_used_fid = *fid;
462 osp->opd_gap_start_fid = *fid;
463 osp->opd_pre_used_fid = *fid;
464 osp->opd_pre_last_created_fid = *fid;
465 spin_unlock(&osp->opd_pre_lock);
471 * Find IDs available in current sequence
473 * The function calculates the highest possible ID and the number of IDs
474 * available in the current sequence OSP is using. The number is limited
475 * artifically by the caller (grow param) and the number of IDs available
476 * in the sequence by nature. The function doesn't require an external
479 * \param[in] env LU environment provided by the caller
480 * \param[in] osp OSP device
481 * \param[in] fid FID the caller wants to start with
482 * \param[in] grow how many the caller wants
483 * \param[out] fid the highest calculated FID
484 * \param[out] grow the number of available IDs calculated
486 * \retval 0 on success, 1 - the sequence is empty
488 static int osp_precreate_fids(const struct lu_env *env, struct osp_device *osp,
489 struct lu_fid *fid, int *grow)
491 struct osp_thread_info *osi = osp_env_info(env);
495 if (fid_is_idif(fid)) {
496 struct lu_fid *last_fid;
497 struct ost_id *oi = &osi->osi_oi;
499 spin_lock(&osp->opd_pre_lock);
500 last_fid = &osp->opd_pre_last_created_fid;
501 fid_to_ostid(last_fid, oi);
502 end = min(ostid_id(oi) + *grow, IDIF_MAX_OID);
503 *grow = end - ostid_id(oi);
504 ostid_set_id(oi, ostid_id(oi) + *grow);
505 spin_unlock(&osp->opd_pre_lock);
510 ostid_to_fid(fid, oi, osp->opd_index);
514 spin_lock(&osp->opd_pre_lock);
515 *fid = osp->opd_pre_last_created_fid;
517 end = min((end + *grow), (__u64)LUSTRE_DATA_SEQ_MAX_WIDTH);
518 *grow = end - fid->f_oid;
519 fid->f_oid += end - fid->f_oid;
520 spin_unlock(&osp->opd_pre_lock);
522 CDEBUG(D_INFO, "Expect %d, actual %d ["DFID" -- "DFID"]\n",
523 *grow, i, PFID(fid), PFID(&osp->opd_pre_last_created_fid));
525 return *grow > 0 ? 0 : 1;
529 * Prepare and send precreate RPC
531 * The function finds how many objects should be precreated. Then allocates,
532 * prepares and schedules precreate RPC synchronously. Upon reply the function
533 * wake ups the threads waiting for the new objects on this target. If the
534 * target wasn't able to create all the objects requested, then the next
535 * precreate will be asking less objects (i.e. slow precreate down).
537 * \param[in] env LU environment provided by the caller
538 * \param[in] d OSP device
540 * \retval 0 on success
541 * \retval negative negated errno on error
543 static int osp_precreate_send(const struct lu_env *env, struct osp_device *d)
545 struct osp_thread_info *oti = osp_env_info(env);
546 struct ptlrpc_request *req;
547 struct obd_import *imp;
548 struct ost_body *body;
550 struct lu_fid *fid = &oti->osi_fid;
553 /* don't precreate new objects till OST healthy and has free space */
554 if (unlikely(d->opd_pre_status)) {
555 CDEBUG(D_INFO, "%s: don't send new precreate: rc = %d\n",
556 d->opd_obd->obd_name, d->opd_pre_status);
561 * if not connection/initialization is compeleted, ignore
563 imp = d->opd_obd->u.cli.cl_import;
566 req = ptlrpc_request_alloc(imp, &RQF_OST_CREATE);
569 req->rq_request_portal = OST_CREATE_PORTAL;
570 /* we should not resend create request - anyway we will have delorphan
571 * and kill these objects */
572 req->rq_no_delay = req->rq_no_resend = 1;
574 rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_CREATE);
576 ptlrpc_request_free(req);
580 spin_lock(&d->opd_pre_lock);
581 if (d->opd_pre_create_count > d->opd_pre_max_create_count / 2)
582 d->opd_pre_create_count = d->opd_pre_max_create_count / 2;
583 grow = d->opd_pre_create_count;
584 spin_unlock(&d->opd_pre_lock);
586 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
589 *fid = d->opd_pre_last_created_fid;
590 rc = osp_precreate_fids(env, d, fid, &grow);
592 /* Current seq has been used up*/
593 if (!osp_is_fid_client(d)) {
594 osp_pre_update_status(d, -ENOSPC);
597 wake_up(&d->opd_pre_waitq);
601 if (!osp_is_fid_client(d)) {
602 /* Non-FID client will always send seq 0 because of
604 LASSERTF(fid_is_idif(fid), "Invalid fid "DFID"\n", PFID(fid));
608 fid_to_ostid(fid, &body->oa.o_oi);
609 body->oa.o_valid = OBD_MD_FLGROUP;
611 ptlrpc_request_set_replen(req);
613 rc = ptlrpc_queue_wait(req);
615 CERROR("%s: can't precreate: rc = %d\n", d->opd_obd->obd_name,
619 LASSERT(req->rq_transno == 0);
621 body = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
623 GOTO(out_req, rc = -EPROTO);
625 ostid_to_fid(fid, &body->oa.o_oi, d->opd_index);
626 if (osp_fid_diff(fid, &d->opd_pre_used_fid) <= 0) {
627 CERROR("%s: precreate fid "DFID" < local used fid "DFID
628 ": rc = %d\n", d->opd_obd->obd_name,
629 PFID(fid), PFID(&d->opd_pre_used_fid), -ESTALE);
630 GOTO(out_req, rc = -ESTALE);
633 diff = osp_fid_diff(fid, &d->opd_pre_last_created_fid);
635 spin_lock(&d->opd_pre_lock);
637 /* the OST has not managed to create all the
638 * objects we asked for */
639 d->opd_pre_create_count = max(diff, OST_MIN_PRECREATE);
640 d->opd_pre_create_slow = 1;
642 /* the OST is able to keep up with the work,
643 * we could consider increasing create_count
644 * next time if needed */
645 d->opd_pre_create_slow = 0;
648 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
649 fid_to_ostid(fid, &body->oa.o_oi);
651 d->opd_pre_last_created_fid = *fid;
652 spin_unlock(&d->opd_pre_lock);
654 CDEBUG(D_HA, "%s: current precreated pool: "DFID"-"DFID"\n",
655 d->opd_obd->obd_name, PFID(&d->opd_pre_used_fid),
656 PFID(&d->opd_pre_last_created_fid));
658 /* now we can wakeup all users awaiting for objects */
659 osp_pre_update_status(d, rc);
660 wake_up(&d->opd_pre_user_waitq);
662 ptlrpc_req_finished(req);
667 * Get last precreated object from target (OST)
669 * Sends synchronous RPC to the target (OST) to learn the last precreated
670 * object. This later is used to remove all unused objects (cleanup orphan
671 * procedure). Also, the next object after one we got will be used as a
672 * starting point for the new precreates.
674 * \param[in] env LU environment provided by the caller
675 * \param[in] d OSP device
677 * \retval 0 on success
678 * \retval negative negated errno on error
680 static int osp_get_lastfid_from_ost(const struct lu_env *env,
681 struct osp_device *d)
683 struct ptlrpc_request *req = NULL;
684 struct obd_import *imp;
685 struct lu_fid *last_fid;
690 imp = d->opd_obd->u.cli.cl_import;
693 req = ptlrpc_request_alloc(imp, &RQF_OST_GET_INFO_LAST_FID);
697 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_KEY, RCL_CLIENT,
698 sizeof(KEY_LAST_FID));
700 rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_GET_INFO);
702 ptlrpc_request_free(req);
706 tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_KEY);
707 memcpy(tmp, KEY_LAST_FID, sizeof(KEY_LAST_FID));
709 req->rq_no_delay = req->rq_no_resend = 1;
710 last_fid = req_capsule_client_get(&req->rq_pill, &RMF_FID);
711 fid_cpu_to_le(last_fid, &d->opd_last_used_fid);
713 ptlrpc_request_set_replen(req);
715 rc = ptlrpc_queue_wait(req);
717 /* bad-bad OST.. let sysadm sort this out */
718 if (rc == -ENOTSUPP) {
719 CERROR("%s: server does not support FID: rc = %d\n",
720 d->opd_obd->obd_name, -ENOTSUPP);
722 ptlrpc_set_import_active(imp, 0);
726 last_fid = req_capsule_server_get(&req->rq_pill, &RMF_FID);
727 if (last_fid == NULL) {
728 CERROR("%s: Got last_fid failed.\n", d->opd_obd->obd_name);
729 GOTO(out, rc = -EPROTO);
732 if (!fid_is_sane(last_fid)) {
733 CERROR("%s: Got insane last_fid "DFID"\n",
734 d->opd_obd->obd_name, PFID(last_fid));
735 GOTO(out, rc = -EPROTO);
738 /* Only update the last used fid, if the OST has objects for
739 * this sequence, i.e. fid_oid > 0 */
740 if (fid_oid(last_fid) > 0)
741 d->opd_last_used_fid = *last_fid;
743 CDEBUG(D_HA, "%s: Got last_fid "DFID"\n", d->opd_obd->obd_name,
747 ptlrpc_req_finished(req);
752 * Cleanup orphans on OST
754 * This function is called in a contex of a dedicated thread handling
755 * all the precreation suff. The function waits till local recovery
756 * is complete, then identify all the unreferenced objects (orphans)
757 * using the highest ID referenced by a local and the highest object
758 * precreated by the target. The found range is a subject to removal
759 * using specially flagged RPC. During this process OSP is marked
760 * unavailable for new objects.
762 * \param[in] env LU environment provided by the caller
763 * \param[in] d OSP device
765 * \retval 0 on success
766 * \retval negative negated errno on error
768 static int osp_precreate_cleanup_orphans(struct lu_env *env,
769 struct osp_device *d)
771 struct osp_thread_info *osi = osp_env_info(env);
772 struct lu_fid *last_fid = &osi->osi_fid;
773 struct ptlrpc_request *req = NULL;
774 struct obd_import *imp;
775 struct ost_body *body;
776 struct l_wait_info lwi = { 0 };
777 int update_status = 0;
784 * wait for local recovery to finish, so we can cleanup orphans
785 * orphans are all objects since "last used" (assigned), but
786 * there might be objects reserved and in some cases they won't
787 * be used. we can't cleanup them till we're sure they won't be
788 * used. also can't we allow new reservations because they may
789 * end up getting orphans being cleaned up below. so we block
790 * new reservations and wait till all reserved objects either
793 spin_lock(&d->opd_pre_lock);
794 d->opd_pre_recovering = 1;
795 spin_unlock(&d->opd_pre_lock);
797 * The locking above makes sure the opd_pre_reserved check below will
798 * catch all osp_precreate_reserve() calls who find
799 * "!opd_pre_recovering".
801 l_wait_event(d->opd_pre_waitq,
802 (!d->opd_pre_reserved && d->opd_recovery_completed) ||
803 !osp_precreate_running(d) || d->opd_got_disconnected,
805 if (!osp_precreate_running(d) || d->opd_got_disconnected)
806 GOTO(out, rc = -EAGAIN);
808 CDEBUG(D_HA, "%s: going to cleanup orphans since "DFID"\n",
809 d->opd_obd->obd_name, PFID(&d->opd_last_used_fid));
811 *last_fid = d->opd_last_used_fid;
812 /* The OSP should already get the valid seq now */
813 LASSERT(!fid_is_zero(last_fid));
814 if (fid_oid(&d->opd_last_used_fid) < 2) {
815 /* lastfid looks strange... ask OST */
816 rc = osp_get_lastfid_from_ost(env, d);
821 imp = d->opd_obd->u.cli.cl_import;
824 req = ptlrpc_request_alloc(imp, &RQF_OST_CREATE);
826 GOTO(out, rc = -ENOMEM);
828 rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_CREATE);
830 ptlrpc_request_free(req);
835 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
837 GOTO(out, rc = -EPROTO);
839 body->oa.o_flags = OBD_FL_DELORPHAN;
840 body->oa.o_valid = OBD_MD_FLFLAGS | OBD_MD_FLGROUP;
842 fid_to_ostid(&d->opd_last_used_fid, &body->oa.o_oi);
844 ptlrpc_request_set_replen(req);
846 /* Don't resend the delorphan req */
847 req->rq_no_resend = req->rq_no_delay = 1;
849 rc = ptlrpc_queue_wait(req);
855 body = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
857 GOTO(out, rc = -EPROTO);
860 * OST provides us with id new pool starts from in body->oa.o_id
862 ostid_to_fid(last_fid, &body->oa.o_oi, d->opd_index);
864 spin_lock(&d->opd_pre_lock);
865 diff = osp_fid_diff(&d->opd_last_used_fid, last_fid);
867 d->opd_pre_create_count = OST_MIN_PRECREATE + diff;
868 d->opd_pre_last_created_fid = d->opd_last_used_fid;
870 d->opd_pre_create_count = OST_MIN_PRECREATE;
871 d->opd_pre_last_created_fid = *last_fid;
874 * This empties the pre-creation pool and effectively blocks any new
877 LASSERT(fid_oid(&d->opd_pre_last_created_fid) <=
878 LUSTRE_DATA_SEQ_MAX_WIDTH);
879 d->opd_pre_used_fid = d->opd_pre_last_created_fid;
880 d->opd_pre_create_slow = 0;
881 spin_unlock(&d->opd_pre_lock);
883 CDEBUG(D_HA, "%s: Got last_id "DFID" from OST, last_created "DFID
884 "last_used is "DFID"\n", d->opd_obd->obd_name, PFID(last_fid),
885 PFID(&d->opd_pre_last_created_fid), PFID(&d->opd_last_used_fid));
888 ptlrpc_req_finished(req);
890 spin_lock(&d->opd_pre_lock);
891 d->opd_pre_recovering = 0;
892 spin_unlock(&d->opd_pre_lock);
895 * If rc is zero, the pre-creation window should have been emptied.
896 * Since waking up the herd would be useless without pre-created
897 * objects, we defer the signal to osp_precreate_send() in that case.
901 CERROR("%s: cannot cleanup orphans: rc = %d\n",
902 d->opd_obd->obd_name, rc);
903 /* we can't proceed from here, OST seem to
904 * be in a bad shape, better to wait for
905 * a new instance of the server and repeat
906 * from the beginning. notify possible waiters
907 * this OSP isn't quite functional yet */
908 osp_pre_update_status(d, rc);
910 wake_up(&d->opd_pre_user_waitq);
918 * Update precreate status using statfs data
920 * The function decides whether this OSP should be used for new objects.
921 * IOW, whether this OST is used up or has some free space. Cached statfs
922 * data is used to make this decision. If the latest result of statfs
923 * request (rc argument) is not success, then just mark OSP unavailable
926 * Add a bit of hysteresis so this flag isn't continually flapping,
927 * and ensure that new files don't get extremely fragmented due to
928 * only a small amount of available space in the filesystem.
929 * We want to set the NOSPC flag when there is less than ~0.1% free
930 * and clear it when there is at least ~0.2% free space, so:
931 * avail < ~0.1% max max = avail + used
932 * 1025 * avail < avail + used used = blocks - free
933 * 1024 * avail < used
934 * 1024 * avail < blocks - free
935 * avail < ((blocks - free) >> 10)
937 * On very large disk, say 16TB 0.1% will be 16 GB. We don't want to
938 * lose that amount of space so in those cases we report no space left
939 * if their is less than 1 GB left.
940 * the function updates current precreation status used: functional or not
942 * \param[in] d OSP device
943 * \param[in] rc new precreate status for device \a d
945 * \retval 0 on success
946 * \retval negative negated errno on error
948 void osp_pre_update_status(struct osp_device *d, int rc)
950 struct obd_statfs *msfs = &d->opd_statfs;
951 int old = d->opd_pre_status;
954 d->opd_pre_status = rc;
958 if (likely(msfs->os_type)) {
959 used = min_t(__u64, (msfs->os_blocks - msfs->os_bfree) >> 10,
961 if ((msfs->os_ffree < 32) || (msfs->os_bavail < used)) {
962 d->opd_pre_status = -ENOSPC;
964 CDEBUG(D_INFO, "%s: status: "LPU64" blocks, "
965 LPU64" free, "LPU64" used, "LPU64" "
966 "avail -> %d: rc = %d\n",
967 d->opd_obd->obd_name, msfs->os_blocks,
968 msfs->os_bfree, used, msfs->os_bavail,
969 d->opd_pre_status, rc);
971 "non-committed changes: %lu, in progress: %u\n",
972 d->opd_syn_changes, d->opd_syn_rpc_in_progress);
973 } else if (old == -ENOSPC) {
974 d->opd_pre_status = 0;
975 spin_lock(&d->opd_pre_lock);
976 d->opd_pre_create_slow = 0;
977 d->opd_pre_create_count = OST_MIN_PRECREATE;
978 spin_unlock(&d->opd_pre_lock);
979 wake_up(&d->opd_pre_waitq);
980 CDEBUG(D_INFO, "%s: no space: "LPU64" blocks, "LPU64
981 " free, "LPU64" used, "LPU64" avail -> %d: "
982 "rc = %d\n", d->opd_obd->obd_name,
983 msfs->os_blocks, msfs->os_bfree, used,
984 msfs->os_bavail, d->opd_pre_status, rc);
989 wake_up(&d->opd_pre_user_waitq);
993 * Initialize FID for precreation
995 * For a just created new target, a new sequence should be taken.
996 * The function checks there is no IDIF in use (if the target was
997 * added with the older version of Lustre), then requests a new
998 * sequence from FLDB using the regular protocol. Then this new
999 * sequence is stored on a persisten storage synchronously to prevent
1000 * possible object leakage (for the detail see the description for
1001 * osp_precreate_rollover_new_seq()).
1003 * \param[in] osp OSP device
1005 * \retval 0 on success
1006 * \retval negative negated errno on error
1008 int osp_init_pre_fid(struct osp_device *osp)
1011 struct osp_thread_info *osi;
1012 struct lu_client_seq *cli_seq;
1013 struct lu_fid *last_fid;
1017 LASSERT(osp->opd_pre != NULL);
1019 /* Return if last_used fid has been initialized */
1020 if (!fid_is_zero(&osp->opd_last_used_fid))
1023 rc = lu_env_init(&env, osp->opd_dt_dev.dd_lu_dev.ld_type->ldt_ctx_tags);
1025 CERROR("%s: init env error: rc = %d\n",
1026 osp->opd_obd->obd_name, rc);
1030 osi = osp_env_info(&env);
1031 last_fid = &osi->osi_fid;
1033 /* For a freshed fs, it will allocate a new sequence first */
1034 if (osp_is_fid_client(osp) && osp->opd_group != 0) {
1035 cli_seq = osp->opd_obd->u.cli.cl_seq;
1036 rc = seq_client_get_seq(&env, cli_seq, &last_fid->f_seq);
1038 CERROR("%s: alloc fid error: rc = %d\n",
1039 osp->opd_obd->obd_name, rc);
1043 last_fid->f_seq = fid_idif_seq(0, osp->opd_index);
1045 last_fid->f_oid = 1;
1046 last_fid->f_ver = 0;
1048 spin_lock(&osp->opd_pre_lock);
1049 osp->opd_last_used_fid = *last_fid;
1050 osp->opd_pre_used_fid = *last_fid;
1051 osp->opd_pre_last_created_fid = *last_fid;
1052 spin_unlock(&osp->opd_pre_lock);
1053 rc = osp_write_last_oid_seq_files(&env, osp, last_fid, 1);
1055 CERROR("%s: write fid error: rc = %d\n",
1056 osp->opd_obd->obd_name, rc);
1065 * The core of precreate functionality
1067 * The function implements the main precreation loop. Basically it
1068 * involves connecting to the target, precerate FID initialization,
1069 * identifying and removing orphans, then serving precreation. As
1070 * part of the latter, the thread is responsible for statfs data
1071 * updates. The precreation is mostly driven by another threads
1072 * asking for new OST objects - those askers wake the thread when
1073 * the number of precreated objects reach low watermark.
1074 * After a disconnect, the sequence above repeats. This is keep going
1075 * until the thread is requested to stop.
1077 * \param[in] _arg private data the thread (OSP device to handle)
1079 * \retval 0 on success
1080 * \retval negative negated errno on error
1082 static int osp_precreate_thread(void *_arg)
1084 struct osp_device *d = _arg;
1085 struct ptlrpc_thread *thread = &d->opd_pre_thread;
1086 struct l_wait_info lwi = { 0 };
1092 rc = lu_env_init(&env, d->opd_dt_dev.dd_lu_dev.ld_type->ldt_ctx_tags);
1094 CERROR("%s: init env error: rc = %d\n", d->opd_obd->obd_name,
1099 spin_lock(&d->opd_pre_lock);
1100 thread->t_flags = SVC_RUNNING;
1101 spin_unlock(&d->opd_pre_lock);
1102 wake_up(&thread->t_ctl_waitq);
1104 while (osp_precreate_running(d)) {
1106 * need to be connected to OST
1108 while (osp_precreate_running(d)) {
1109 l_wait_event(d->opd_pre_waitq,
1110 !osp_precreate_running(d) ||
1111 d->opd_new_connection,
1114 if (!d->opd_new_connection)
1117 d->opd_new_connection = 0;
1118 d->opd_got_disconnected = 0;
1122 if (!osp_precreate_running(d))
1125 LASSERT(d->opd_obd->u.cli.cl_seq != NULL);
1126 /* Sigh, fid client is not ready yet */
1127 if (d->opd_obd->u.cli.cl_seq->lcs_exp == NULL)
1130 /* Init fid for osp_precreate if necessary */
1131 rc = osp_init_pre_fid(d);
1133 class_export_put(d->opd_exp);
1134 d->opd_obd->u.cli.cl_seq->lcs_exp = NULL;
1135 CERROR("%s: init pre fid error: rc = %d\n",
1136 d->opd_obd->obd_name, rc);
1140 osp_statfs_update(d);
1143 * Clean up orphans or recreate missing objects.
1145 rc = osp_precreate_cleanup_orphans(&env, d);
1149 * connected, can handle precreates now
1151 while (osp_precreate_running(d)) {
1152 l_wait_event(d->opd_pre_waitq,
1153 !osp_precreate_running(d) ||
1154 osp_precreate_near_empty(&env, d) ||
1155 osp_statfs_need_update(d) ||
1156 d->opd_got_disconnected, &lwi);
1158 if (!osp_precreate_running(d))
1161 /* something happened to the connection
1162 * have to start from the beginning */
1163 if (d->opd_got_disconnected)
1166 if (osp_statfs_need_update(d))
1167 osp_statfs_update(d);
1169 /* To avoid handling different seq in precreate/orphan
1170 * cleanup, it will hold precreate until current seq is
1172 if (unlikely(osp_precreate_end_seq(&env, d) &&
1173 !osp_create_end_seq(&env, d)))
1176 if (unlikely(osp_precreate_end_seq(&env, d) &&
1177 osp_create_end_seq(&env, d))) {
1178 LCONSOLE_INFO("%s:"LPX64" is used up."
1179 " Update to new seq\n",
1180 d->opd_obd->obd_name,
1181 fid_seq(&d->opd_pre_last_created_fid));
1182 rc = osp_precreate_rollover_new_seq(&env, d);
1187 if (osp_precreate_near_empty(&env, d)) {
1188 rc = osp_precreate_send(&env, d);
1189 /* osp_precreate_send() sets opd_pre_status
1190 * in case of error, that prevent the using of
1192 if (rc < 0 && rc != -ENOSPC &&
1193 rc != -ETIMEDOUT && rc != -ENOTCONN)
1194 CERROR("%s: cannot precreate objects:"
1196 d->opd_obd->obd_name, rc);
1201 thread->t_flags = SVC_STOPPED;
1203 wake_up(&thread->t_ctl_waitq);
1209 * Check when to stop to wait for precreate objects.
1211 * The caller wanting a new OST object can't wait undefinitely. The
1212 * function checks for few conditions including available new OST
1213 * objects, disconnected OST, lack of space with no pending destroys,
1214 * etc. IOW, it checks whether the current OSP state is good to keep
1215 * waiting or it's better to give up.
1217 * \param[in] env LU environment provided by the caller
1218 * \param[in] d OSP device
1220 * \retval 0 - keep waiting, 1 - no luck
1222 static int osp_precreate_ready_condition(const struct lu_env *env,
1223 struct osp_device *d)
1225 if (d->opd_pre_recovering)
1228 /* ready if got enough precreated objects */
1229 /* we need to wait for others (opd_pre_reserved) and our object (+1) */
1230 if (d->opd_pre_reserved + 1 < osp_objs_precreated(env, d))
1233 /* ready if OST reported no space and no destroys in progress */
1234 if (d->opd_syn_changes + d->opd_syn_rpc_in_progress == 0 &&
1235 d->opd_pre_status == -ENOSPC)
1238 /* Bail out I/O fails to OST */
1239 if (d->opd_pre_status != 0 &&
1240 d->opd_pre_status != -EAGAIN &&
1241 d->opd_pre_status != -ENODEV &&
1242 d->opd_pre_status != -ENOSPC) {
1244 if (d->opd_pre_status != -EIO)
1245 CERROR("%s: precreate failed opd_pre_status %d\n",
1246 d->opd_obd->obd_name, d->opd_pre_status);
1253 static int osp_precreate_timeout_condition(void *data)
1255 struct osp_device *d = data;
1257 CDEBUG(D_HA, "%s: slow creates, last="DFID", next="DFID", "
1258 "reserved="LPU64", syn_changes=%lu, "
1259 "syn_rpc_in_progress=%d, status=%d\n",
1260 d->opd_obd->obd_name, PFID(&d->opd_pre_last_created_fid),
1261 PFID(&d->opd_pre_used_fid), d->opd_pre_reserved,
1262 d->opd_syn_changes, d->opd_syn_rpc_in_progress,
1269 * Reserve object in precreate pool
1271 * When the caller wants to create a new object on this target (target
1272 * represented by the given OSP), it should declare this intention using
1273 * a regular ->dt_declare_create() OSD API method. Then OSP will be trying
1274 * to reserve an object in the existing precreated pool or wait up to
1275 * obd_timeout for the available object to appear in the pool (a dedicated
1276 * thread will be doing real precreation in background). The object can be
1277 * consumed later with osp_precreate_get_fid() or be released with call to
1278 * lu_object_put(). Notice the function doesn't reserve a specific ID, just
1279 * some ID. The actual ID assignment happen in osp_precreate_get_fid().
1280 * If the space on the target is short and there is a pending object destroy,
1281 * then the function forces local commit to speedup space release (see
1282 * osp_sync.c for the details).
1284 * \param[in] env LU environment provided by the caller
1285 * \param[in] d OSP device
1287 * \retval 0 on success
1288 * \retval -ENOSPC when no space on OST
1289 * \retval -EAGAIN try later, slow precreation in progress
1290 * \retval -EIO when no access to OST
1292 int osp_precreate_reserve(const struct lu_env *env, struct osp_device *d)
1294 struct l_wait_info lwi;
1295 cfs_time_t expire = cfs_time_shift(obd_timeout);
1300 LASSERTF(osp_objs_precreated(env, d) >= 0, "Last created FID "DFID
1301 "Next FID "DFID"\n", PFID(&d->opd_pre_last_created_fid),
1302 PFID(&d->opd_pre_used_fid));
1306 * - preallocation is done
1307 * - no free space expected soon
1308 * - can't connect to OST for too long (obd_timeout)
1309 * - OST can allocate fid sequence.
1311 while ((rc = d->opd_pre_status) == 0 || rc == -ENOSPC ||
1312 rc == -ENODEV || rc == -EAGAIN || rc == -ENOTCONN) {
1315 * increase number of precreations
1317 precreated = osp_objs_precreated(env, d);
1318 if (d->opd_pre_create_count < d->opd_pre_max_create_count &&
1319 d->opd_pre_create_slow == 0 &&
1320 precreated <= (d->opd_pre_create_count / 4 + 1)) {
1321 spin_lock(&d->opd_pre_lock);
1322 d->opd_pre_create_slow = 1;
1323 d->opd_pre_create_count *= 2;
1324 spin_unlock(&d->opd_pre_lock);
1327 spin_lock(&d->opd_pre_lock);
1328 precreated = osp_objs_precreated(env, d);
1329 if (precreated > d->opd_pre_reserved &&
1330 !d->opd_pre_recovering) {
1331 d->opd_pre_reserved++;
1332 spin_unlock(&d->opd_pre_lock);
1335 /* XXX: don't wake up if precreation is in progress */
1336 if (osp_precreate_near_empty_nolock(env, d) &&
1337 !osp_precreate_end_seq_nolock(env, d))
1338 wake_up(&d->opd_pre_waitq);
1342 spin_unlock(&d->opd_pre_lock);
1345 * all precreated objects have been used and no-space
1346 * status leave us no chance to succeed very soon
1347 * but if there is destroy in progress, then we should
1348 * wait till that is done - some space might be released
1350 if (unlikely(rc == -ENOSPC)) {
1351 if (d->opd_syn_changes) {
1352 /* force local commit to release space */
1353 dt_commit_async(env, d->opd_storage);
1355 if (d->opd_syn_rpc_in_progress) {
1356 /* just wait till destroys are done */
1357 /* see l_wait_even() few lines below */
1359 if (d->opd_syn_changes +
1360 d->opd_syn_rpc_in_progress == 0) {
1361 /* no hope for free space */
1366 /* XXX: don't wake up if precreation is in progress */
1367 wake_up(&d->opd_pre_waitq);
1369 lwi = LWI_TIMEOUT(expire - cfs_time_current(),
1370 osp_precreate_timeout_condition, d);
1371 if (cfs_time_aftereq(cfs_time_current(), expire)) {
1376 l_wait_event(d->opd_pre_user_waitq,
1377 osp_precreate_ready_condition(env, d), &lwi);
1384 * Get a FID from precreation pool
1386 * The function is a companion for osp_precreate_reserve() - it assigns
1387 * a specific FID from the precreate. The function should be called only
1388 * if the call to osp_precreate_reserve() was successful. The function
1389 * updates a local storage to remember the highest object ID referenced
1390 * by the node in the given sequence.
1392 * A very importan details: this is supposed to be called once the
1393 * transaction is started, so on-disk update will be atomic with the
1394 * data (like LOVEA) refering this object. Then the object won't be leaked:
1395 * either it's referenced by the committed transaction or it's a subject
1396 * to the orphan cleanup procedure.
1398 * \param[in] env LU environment provided by the caller
1399 * \param[in] d OSP device
1400 * \param[out] fid generated FID
1402 * \retval 0 on success
1403 * \retval negative negated errno on error
1405 int osp_precreate_get_fid(const struct lu_env *env, struct osp_device *d,
1408 /* grab next id from the pool */
1409 spin_lock(&d->opd_pre_lock);
1411 LASSERTF(osp_fid_diff(&d->opd_pre_used_fid,
1412 &d->opd_pre_last_created_fid) < 0,
1413 "next fid "DFID" last created fid "DFID"\n",
1414 PFID(&d->opd_pre_used_fid),
1415 PFID(&d->opd_pre_last_created_fid));
1417 d->opd_pre_used_fid.f_oid++;
1418 memcpy(fid, &d->opd_pre_used_fid, sizeof(*fid));
1419 d->opd_pre_reserved--;
1421 * last_used_id must be changed along with getting new id otherwise
1422 * we might miscalculate gap causing object loss or leak
1424 osp_update_last_fid(d, fid);
1425 spin_unlock(&d->opd_pre_lock);
1428 * probably main thread suspended orphan cleanup till
1429 * all reservations are released, see comment in
1430 * osp_precreate_thread() just before orphan cleanup
1432 if (unlikely(d->opd_pre_reserved == 0 && d->opd_pre_status))
1433 wake_up(&d->opd_pre_waitq);
1439 * Set size regular attribute on an object
1441 * When a striping is created late, it's possible that size is already
1442 * initialized on the file. Then the new striping should inherit size
1443 * from the file. The function sets size on the object using the regular
1444 * protocol (OST_PUNCH).
1445 * XXX: should be re-implemented using OUT ?
1447 * \param[in] env LU environment provided by the caller
1448 * \param[in] dt object
1449 * \param[in] size size to set.
1451 * \retval 0 on success
1452 * \retval negative negated errno on error
1454 int osp_object_truncate(const struct lu_env *env, struct dt_object *dt,
1457 struct osp_device *d = lu2osp_dev(dt->do_lu.lo_dev);
1458 struct ptlrpc_request *req = NULL;
1459 struct obd_import *imp;
1460 struct ost_body *body;
1461 struct obdo *oa = NULL;
1466 imp = d->opd_obd->u.cli.cl_import;
1469 req = ptlrpc_request_alloc(imp, &RQF_OST_PUNCH);
1473 /* XXX: capa support? */
1474 /* osc_set_capa_size(req, &RMF_CAPA1, capa); */
1475 rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_PUNCH);
1477 ptlrpc_request_free(req);
1482 * XXX: decide how do we do here with resend
1483 * if we don't resend, then client may see wrong file size
1484 * if we do resend, then MDS thread can get stuck for quite long
1486 req->rq_no_resend = req->rq_no_delay = 1;
1488 req->rq_request_portal = OST_IO_PORTAL; /* bug 7198 */
1489 ptlrpc_at_set_req_timeout(req);
1493 GOTO(out, rc = -ENOMEM);
1495 rc = fid_to_ostid(lu_object_fid(&dt->do_lu), &oa->o_oi);
1498 oa->o_blocks = OBD_OBJECT_EOF;
1499 oa->o_valid = OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
1500 OBD_MD_FLID | OBD_MD_FLGROUP;
1502 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1504 lustre_set_wire_obdo(&req->rq_import->imp_connect_data, &body->oa, oa);
1506 /* XXX: capa support? */
1507 /* osc_pack_capa(req, body, capa); */
1509 ptlrpc_request_set_replen(req);
1511 rc = ptlrpc_queue_wait(req);
1513 CERROR("can't punch object: %d\n", rc);
1515 ptlrpc_req_finished(req);
1522 * Initialize precreation functionality of OSP
1524 * Prepares all the internal structures and starts the precreate thread
1526 * \param[in] d OSP device
1528 * \retval 0 on success
1529 * \retval negative negated errno on error
1531 int osp_init_precreate(struct osp_device *d)
1533 struct l_wait_info lwi = { 0 };
1534 struct task_struct *task;
1538 OBD_ALLOC_PTR(d->opd_pre);
1539 if (d->opd_pre == NULL)
1542 /* initially precreation isn't ready */
1543 d->opd_pre_status = -EAGAIN;
1544 fid_zero(&d->opd_pre_used_fid);
1545 d->opd_pre_used_fid.f_oid = 1;
1546 fid_zero(&d->opd_pre_last_created_fid);
1547 d->opd_pre_last_created_fid.f_oid = 1;
1548 d->opd_pre_reserved = 0;
1549 d->opd_got_disconnected = 1;
1550 d->opd_pre_create_slow = 0;
1551 d->opd_pre_create_count = OST_MIN_PRECREATE;
1552 d->opd_pre_min_create_count = OST_MIN_PRECREATE;
1553 d->opd_pre_max_create_count = OST_MAX_PRECREATE;
1555 spin_lock_init(&d->opd_pre_lock);
1556 init_waitqueue_head(&d->opd_pre_waitq);
1557 init_waitqueue_head(&d->opd_pre_user_waitq);
1558 init_waitqueue_head(&d->opd_pre_thread.t_ctl_waitq);
1561 * Initialize statfs-related things
1563 d->opd_statfs_maxage = 5; /* default update interval */
1564 d->opd_statfs_fresh_till = cfs_time_shift(-1000);
1565 CDEBUG(D_OTHER, "current %llu, fresh till %llu\n",
1566 (unsigned long long)cfs_time_current(),
1567 (unsigned long long)d->opd_statfs_fresh_till);
1568 cfs_timer_init(&d->opd_statfs_timer, osp_statfs_timer_cb, d);
1571 * start thread handling precreation and statfs updates
1573 task = kthread_run(osp_precreate_thread, d,
1574 "osp-pre-%u-%u", d->opd_index, d->opd_group);
1576 CERROR("can't start precreate thread %ld\n", PTR_ERR(task));
1577 RETURN(PTR_ERR(task));
1580 l_wait_event(d->opd_pre_thread.t_ctl_waitq,
1581 osp_precreate_running(d) || osp_precreate_stopped(d),
1588 * Finish precreate functionality of OSP
1591 * Asks all the activity (the thread, update timer) to stop, then
1592 * wait till that is done.
1594 * \param[in] d OSP device
1596 void osp_precreate_fini(struct osp_device *d)
1598 struct ptlrpc_thread *thread;
1602 cfs_timer_disarm(&d->opd_statfs_timer);
1604 if (d->opd_pre == NULL)
1607 thread = &d->opd_pre_thread;
1609 thread->t_flags = SVC_STOPPING;
1610 wake_up(&d->opd_pre_waitq);
1612 wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_STOPPED);
1614 OBD_FREE_PTR(d->opd_pre);