Whamcloud - gitweb
LU-8066 mdt: migrate procfs files to sysfs
[fs/lustre-release.git] / lustre / mdt / mdt_hsm_cdt_agent.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,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License version 2 for more details.  A copy is
14  * included in the COPYING file that accompanied this code.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * GPL HEADER END
21  */
22 /*
23  * (C) Copyright 2012 Commissariat a l'energie atomique et aux energies
24  *
25  * Copyright (c) 2016, 2017, Intel Corporation.
26  *     alternatives
27  *
28  */
29 /*
30  * lustre/mdt/mdt_hsm_cdt_agent.c
31  *
32  * Lustre HSM Coordinator
33  *
34  * Author: Jacques-Charles Lafoucriere <jacques-charles.lafoucriere@cea.fr>
35  * Author: Aurelien Degremont <aurelien.degremont@cea.fr>
36  */
37
38 #define DEBUG_SUBSYSTEM S_MDS
39
40 #include <obd.h>
41 #include <obd_support.h>
42 #include <lustre_export.h>
43 #include <lprocfs_status.h>
44 #include <lustre_kernelcomm.h>
45 #include "mdt_internal.h"
46
47 /*
48  * Agent external API
49  */
50
51 /*
52  * find a hsm_agent by uuid
53  * lock cdt_agent_lock needs to be held by caller
54  * \param cdt [IN] coordinator
55  * \param uuid [IN] agent UUID
56  * \retval hsm_agent pointer or NULL if not found
57  */
58 static struct hsm_agent *mdt_hsm_agent_lookup(struct coordinator *cdt,
59                                               const struct obd_uuid *uuid)
60 {
61         struct hsm_agent        *ha;
62
63         list_for_each_entry(ha, &cdt->cdt_agents, ha_list) {
64                 if (obd_uuid_equals(&ha->ha_uuid, uuid))
65                         return ha;
66         }
67         return NULL;
68 }
69
70 /**
71  * register a copy tool
72  * \param mti [IN] MDT context
73  * \param uuid [IN] client UUID to be registered
74  * \param count [IN] number of archives agent serves
75  * \param archive_id [IN] vector of archive number served by the copytool
76  * \retval 0 success
77  * \retval -ve failure
78  */
79 int mdt_hsm_agent_register(struct mdt_thread_info *mti,
80                            const struct obd_uuid *uuid,
81                            int nr_archives, __u32 *archive_id)
82 {
83         struct coordinator      *cdt = &mti->mti_mdt->mdt_coordinator;
84         struct hsm_agent        *ha, *tmp;
85         int                      rc;
86         ENTRY;
87
88         /* no coordinator started, so we cannot serve requests */
89         if (cdt->cdt_state == CDT_STOPPED) {
90                 LCONSOLE_WARN("HSM coordinator thread is not running - "
91                               "denying agent registration.\n");
92                 RETURN(-ENXIO);
93         }
94
95         OBD_ALLOC_PTR(ha);
96         if (ha == NULL)
97                 GOTO(out, rc = -ENOMEM);
98
99         ha->ha_uuid = *uuid;
100         ha->ha_archive_cnt = nr_archives;
101         if (ha->ha_archive_cnt != 0) {
102                 int sz;
103
104                 sz = ha->ha_archive_cnt * sizeof(*ha->ha_archive_id);
105                 OBD_ALLOC(ha->ha_archive_id, sz);
106                 if (ha->ha_archive_id == NULL)
107                         GOTO(out_free, rc = -ENOMEM);
108                 memcpy(ha->ha_archive_id, archive_id, sz);
109         }
110         atomic_set(&ha->ha_requests, 0);
111         atomic_set(&ha->ha_success, 0);
112         atomic_set(&ha->ha_failure, 0);
113
114         down_write(&cdt->cdt_agent_lock);
115         tmp = mdt_hsm_agent_lookup(cdt, uuid);
116         if (tmp != NULL) {
117                 LCONSOLE_WARN("HSM agent %s already registered\n",
118                               obd_uuid2str(uuid));
119                 up_write(&cdt->cdt_agent_lock);
120                 GOTO(out_free, rc = -EEXIST);
121         }
122
123         list_add_tail(&ha->ha_list, &cdt->cdt_agents);
124
125         if (ha->ha_archive_cnt == 0)
126                 CDEBUG(D_HSM, "agent %s registered for all archives\n",
127                        obd_uuid2str(&ha->ha_uuid));
128         else
129                 CDEBUG(D_HSM, "agent %s registered for %d archives\n",
130                        obd_uuid2str(&ha->ha_uuid), ha->ha_archive_cnt);
131
132         up_write(&cdt->cdt_agent_lock);
133         GOTO(out, rc = 0);
134
135 out_free:
136
137         if (ha != NULL && ha->ha_archive_id != NULL)
138                 OBD_FREE(ha->ha_archive_id,
139                          ha->ha_archive_cnt * sizeof(*ha->ha_archive_id));
140         if (ha != NULL)
141                 OBD_FREE_PTR(ha);
142 out:
143         /* wake the coordinator to potentially schedule requests */
144         if (rc == -EEXIST || rc == 0)
145                 mdt_hsm_cdt_event(cdt);
146
147         return rc;
148 }
149
150 /**
151  * register a copy tool
152  * \param mti [IN] MDT context
153  * \param uuid [IN] uuid to be registered
154  * \param archive_mask [IN] bitmask of archive number served by the copytool
155  * \retval 0 success
156  * \retval -ve failure
157  */
158 int mdt_hsm_agent_register_mask(struct mdt_thread_info *mti,
159                                 const struct obd_uuid *uuid, __u32 archive_mask)
160 {
161         int              rc, i, nr_archives = 0;
162         __u32           *archive_id = NULL;
163         ENTRY;
164
165         nr_archives = hweight32(archive_mask);
166
167         if (nr_archives != 0) {
168                 OBD_ALLOC(archive_id, nr_archives * sizeof(*archive_id));
169                 if (!archive_id)
170                         RETURN(-ENOMEM);
171
172                 nr_archives = 0;
173                 for (i = 0; i < sizeof(archive_mask) * 8; i++) {
174                         if ((1 << i) & archive_mask) {
175                                 archive_id[nr_archives] = i + 1;
176                                 nr_archives++;
177                         }
178                 }
179         }
180
181         rc = mdt_hsm_agent_register(mti, uuid, nr_archives, archive_id);
182
183         if (archive_id != NULL)
184                 OBD_FREE(archive_id, nr_archives * sizeof(*archive_id));
185
186         RETURN(rc);
187 }
188
189 /**
190  * unregister a copy tool
191  * \param mti [IN] MDT context
192  * \param uuid [IN] uuid to be unregistered
193  * \retval 0 success
194  * \retval -ve failure
195  */
196 int mdt_hsm_agent_unregister(struct mdt_thread_info *mti,
197                              const struct obd_uuid *uuid)
198 {
199         struct coordinator      *cdt = &mti->mti_mdt->mdt_coordinator;
200         struct hsm_agent        *ha;
201         int                      rc;
202         ENTRY;
203
204         /* no coordinator started, so we cannot serve requests */
205         if (cdt->cdt_state == CDT_STOPPED)
206                 RETURN(-ENXIO);
207
208         down_write(&cdt->cdt_agent_lock);
209
210         ha = mdt_hsm_agent_lookup(cdt, uuid);
211         if (ha != NULL)
212                 list_del_init(&ha->ha_list);
213
214         up_write(&cdt->cdt_agent_lock);
215
216         if (ha == NULL)
217                 GOTO(out, rc = -ENOENT);
218
219         if (ha->ha_archive_cnt != 0)
220                 OBD_FREE(ha->ha_archive_id,
221                          ha->ha_archive_cnt * sizeof(*ha->ha_archive_id));
222         OBD_FREE_PTR(ha);
223
224         GOTO(out, rc = 0);
225 out:
226         CDEBUG(D_HSM, "agent %s unregistration: %d\n", obd_uuid2str(uuid), rc);
227
228         return rc;
229 }
230
231 /**
232  * update agent statistics
233  * \param mdt [IN] MDT device
234  * \param succ_rq [IN] number of success
235  * \param fail_rq [IN] number of failure
236  * \param new_rq [IN] number of new requests
237  * \param uuid [IN] agent uuid
238  * if all counters == 0, clear counters
239  * \retval 0 success
240  * \retval -ve failure
241  */
242 int mdt_hsm_agent_update_statistics(struct coordinator *cdt,
243                                     int succ_rq, int fail_rq, int new_rq,
244                                     const struct obd_uuid *uuid)
245 {
246         struct hsm_agent        *ha;
247         int                      rc;
248         ENTRY;
249
250         down_read(&cdt->cdt_agent_lock);
251         list_for_each_entry(ha, &cdt->cdt_agents, ha_list) {
252                 if (obd_uuid_equals(&ha->ha_uuid, uuid)) {
253                         if (succ_rq == 0 && fail_rq == 0 && new_rq == 0) {
254                                 atomic_set(&ha->ha_success, 0);
255                                 atomic_set(&ha->ha_failure, 0);
256                                 atomic_set(&ha->ha_requests, 0);
257                         } else {
258                                 atomic_add(succ_rq, &ha->ha_success);
259                                 atomic_add(fail_rq, &ha->ha_failure);
260                                 atomic_add(new_rq, &ha->ha_requests);
261                                 atomic_sub(succ_rq, &ha->ha_requests);
262                                 atomic_sub(fail_rq, &ha->ha_requests);
263                         }
264                         GOTO(out, rc = 0);
265                 }
266
267         }
268         rc = -ENOENT;
269 out:
270         up_read(&cdt->cdt_agent_lock);
271         RETURN(rc);
272 }
273
274 /**
275  * find the best agent
276  * \param cdt [IN] coordinator
277  * \param archive [IN] archive number
278  * \param uuid [OUT] agent who can serve archive
279  * \retval 0 success
280  * \retval -ve failure
281  */
282 int mdt_hsm_find_best_agent(struct coordinator *cdt, __u32 archive,
283                             struct obd_uuid *uuid)
284 {
285         int                      rc = -EAGAIN, i, load = -1;
286         struct hsm_agent        *ha;
287         ENTRY;
288
289         /* Choose an export to send a copytool req to */
290         down_read(&cdt->cdt_agent_lock);
291         list_for_each_entry(ha, &cdt->cdt_agents, ha_list) {
292                 for (i = 0; (i < ha->ha_archive_cnt) &&
293                               (ha->ha_archive_id[i] != archive); i++) {
294                         /* nothing to do, just skip unmatching records */
295                 }
296
297                 /* archive count == 0 means copy tool serves any backend */
298                 if (ha->ha_archive_cnt != 0 && i == ha->ha_archive_cnt)
299                         continue;
300
301                 if (load == -1 || load > atomic_read(&ha->ha_requests)) {
302                         load = atomic_read(&ha->ha_requests);
303                         *uuid = ha->ha_uuid;
304                         rc = 0;
305                 }
306                 if (atomic_read(&ha->ha_requests) == 0)
307                         break;
308         }
309         up_read(&cdt->cdt_agent_lock);
310
311         RETURN(rc);
312 }
313
314 int mdt_hsm_send_action_to_each_archive(struct mdt_thread_info *mti,
315                                     struct hsm_action_item *hai)
316 {
317         struct hsm_agent *ha;
318         __u32 archive_mask = 0;
319         struct coordinator *cdt = &mti->mti_mdt->mdt_coordinator;
320         int i;
321         /* return error by default in case all archive_ids have unregistered */
322         int rc = -EAGAIN;
323         ENTRY;
324
325         /* send action to all registered archive_ids */
326         down_read(&cdt->cdt_agent_lock);
327         list_for_each_entry(ha, &cdt->cdt_agents, ha_list) {
328                 for (i = 0; (i < ha->ha_archive_cnt); i++) {
329                         /* only send once for each archive_id */
330                         if ((1 << ha->ha_archive_id[i]) & archive_mask)
331                                 continue;
332                         archive_mask |= (1 << ha->ha_archive_id[i]);
333
334                         /* XXX: it could make sense to gather all
335                          * actions for the same archive_id like in
336                          * mdt_hsm_add_actions() ?? */
337                         rc = mdt_agent_record_add(mti->mti_env, mti->mti_mdt,
338                                                   ha->ha_archive_id[i], 0,
339                                                   hai);
340                         if (rc) {
341                                 CERROR("%s: unable to add HSM remove request "
342                                        "for "DFID": rc=%d\n",
343                                        mdt_obd_name(mti->mti_mdt),
344                                        PFID(&hai->hai_fid), rc);
345                                 break;
346                         } else {
347                                 CDEBUG(D_HSM, "%s: added HSM remove request "
348                                        "for "DFID", archive_id=%d\n",
349                                        mdt_obd_name(mti->mti_mdt),
350                                        PFID(&hai->hai_fid),
351                                        ha->ha_archive_id[i]);
352                         }
353                 }
354                 /* early exit from loop due to error? */
355                 if (i != ha->ha_archive_cnt)
356                         break;
357         }
358         up_read(&cdt->cdt_agent_lock);
359
360         RETURN(rc);
361 }
362
363 /**
364  * send a HAL to the agent
365  * \param mti [IN] context
366  * \param hal [IN] request (can be a kuc payload)
367  * \param purge [IN] purge mode (no record)
368  * \retval 0 success
369  * \retval -ve failure
370  * This function supposes:
371  *  - all actions are for the same archive number
372  *  - in case of cancel, all cancel are for the same agent
373  * This implies that request split has to be done
374  *  before when building the hal
375  */
376 int mdt_hsm_agent_send(struct mdt_thread_info *mti,
377                        struct hsm_action_list *hal, bool purge)
378 {
379         struct obd_export       *exp;
380         struct mdt_device       *mdt = mti->mti_mdt;
381         struct coordinator      *cdt = &mti->mti_mdt->mdt_coordinator;
382         struct hsm_action_list  *buf = NULL;
383         struct hsm_action_item  *hai;
384         struct obd_uuid          uuid;
385         int                      len, i, rc = 0;
386         bool                     fail_request;
387         bool                     is_registered = false;
388         ENTRY;
389
390         rc = mdt_hsm_find_best_agent(cdt, hal->hal_archive_id, &uuid);
391         if (rc && hal->hal_archive_id == 0) {
392                 uint notrmcount = 0;
393                 int rc2 = 0;
394
395                 /* special case of remove requests with no archive_id specified,
396                  * and no agent registered to serve all archives, then create a
397                  * set of new requests, each to be sent to each registered
398                  * archives.
399                  * Todo so, find all HSMA_REMOVE entries, and then :
400                  *     _ set completed status as SUCCESS (or FAIL?)
401                  *     _ create a new LLOG record for each archive_id
402                  *       presently being served by any CT
403                  */
404                 hai = hai_first(hal);
405                 for (i = 0; i < hal->hal_count; i++,
406                      hai = hai_next(hai)) {
407                         struct hsm_record_update update;
408
409                         /* only removes are concerned */
410                         if (hai->hai_action != HSMA_REMOVE) {
411                                 /* count if other actions than HSMA_REMOVE,
412                                  * to return original error/rc */
413                                 notrmcount++;
414                                 continue;
415                         }
416
417                         /* send remove request to all registered archive_ids */
418                         rc2 = mdt_hsm_send_action_to_each_archive(mti, hai);
419                         if (rc2)
420                                 break;
421
422                         /* only update original request as SUCCEED if it has
423                          * been successfully broadcasted to all available
424                          * archive_ids
425                          * XXX: this should only cause duplicates to be sent,
426                          * unless a method to record already successfully
427                          * reached archive_ids is implemented */
428
429                         update.cookie = hai->hai_cookie;
430                         update.status = ARS_SUCCEED;
431                         rc2 = mdt_agent_record_update(mti->mti_env, mdt,
432                                                       &update, 1);
433                         if (rc2) {
434                                 CERROR("%s: mdt_agent_record_update() "
435                                       "failed, cannot update "
436                                       "status to %s for cookie "
437                                       "%#llx: rc = %d\n",
438                                       mdt_obd_name(mdt),
439                                       agent_req_status2name(ARS_SUCCEED),
440                                       hai->hai_cookie, rc2);
441                                 break;
442                         }
443                 }
444                 /* only remove requests with archive_id=0 */
445                 if (notrmcount == 0)
446                         RETURN(rc2);
447
448         }
449
450         if (rc) {
451                 CERROR("%s: Cannot find agent for archive %d: rc = %d\n",
452                        mdt_obd_name(mdt), hal->hal_archive_id, rc);
453                 RETURN(rc);
454         }
455
456         CDEBUG(D_HSM, "Agent %s selected for archive %d\n", obd_uuid2str(&uuid),
457                hal->hal_archive_id);
458
459         len = hal_size(hal);
460         buf = kuc_alloc(len, KUC_TRANSPORT_HSM, HMT_ACTION_LIST);
461         if (IS_ERR(buf))
462                 RETURN(PTR_ERR(buf));
463         memcpy(buf, hal, len);
464
465         /* Check if request is still valid (cf file hsm flags) */
466         fail_request = false;
467         hai = hai_first(hal);
468         for (i = 0; i < hal->hal_count; i++, hai = hai_next(hai)) {
469                 struct mdt_object *obj;
470                 struct md_hsm hsm;
471
472                 if (hai->hai_action == HSMA_CANCEL)
473                         continue;
474
475                 obj = mdt_hsm_get_md_hsm(mti, &hai->hai_fid, &hsm);
476                 if (!IS_ERR(obj)) {
477                         mdt_object_put(mti->mti_env, obj);
478                 } else if (PTR_ERR(obj) == -ENOENT) {
479                         struct hsm_record_update update = {
480                                 .cookie = hai->hai_cookie,
481                                 .status = ARS_FAILED,
482                         };
483
484                         if (hai->hai_action == HSMA_REMOVE)
485                                 continue;
486
487                         fail_request = true;
488                         rc = mdt_agent_record_update(mti->mti_env, mdt,
489                                                      &update, 1);
490                         if (rc < 0) {
491                                 CERROR("%s: mdt_agent_record_update() failed, "
492                                        "cannot update status to %s for cookie "
493                                        "%#llx: rc = %d\n",
494                                        mdt_obd_name(mdt),
495                                        agent_req_status2name(ARS_FAILED),
496                                        hai->hai_cookie, rc);
497                                 GOTO(out_buf, rc);
498                         }
499
500                         continue;
501                 } else {
502                         GOTO(out_buf, rc = PTR_ERR(obj));
503                 }
504
505                 if (!mdt_hsm_is_action_compat(hai, hal->hal_archive_id,
506                                               hal->hal_flags, &hsm)) {
507                         struct hsm_record_update update = {
508                                 .cookie = hai->hai_cookie,
509                                 .status = ARS_FAILED,
510                         };
511
512                         /* incompatible request, we abort the request */
513                         /* next time coordinator will wake up, it will
514                          * make the same HAL with valid only
515                          * records */
516                         fail_request = true;
517                         rc = mdt_agent_record_update(mti->mti_env, mdt,
518                                                      &update, 1);
519                         if (rc) {
520                                 CERROR("%s: mdt_agent_record_update() failed, "
521                                        "cannot update status to %s for cookie "
522                                        "%#llx: rc = %d\n",
523                                        mdt_obd_name(mdt),
524                                        agent_req_status2name(ARS_FAILED),
525                                        hai->hai_cookie, rc);
526                                 GOTO(out_buf, rc);
527                         }
528
529                         /* if restore and record status updated, give
530                          * back granted layout lock */
531                         if (hai->hai_action == HSMA_RESTORE)
532                                 cdt_restore_handle_del(mti, cdt, &hai->hai_fid);
533                 }
534         }
535
536         /* we found incompatible requests, so the HAL cannot be sent
537          * as is. Bad records have been invalidated in llog.
538          * Valid one will be reschedule next time coordinator will wake up
539          * So no need the rebuild a full valid HAL now
540          */
541         if (fail_request)
542                 GOTO(out_buf, rc = 0);
543
544         /* Cancel memory registration is useless for purge
545          * non registration avoid a deadlock :
546          * in case of failure we have to take the write lock
547          * to remove entry which conflict with the read loack needed
548          * by purge
549          */
550         if (!purge) {
551                 /* set is_registered even if failure because we may have
552                  * partial work done */
553                 is_registered = true;
554                 rc = mdt_hsm_add_hal(mti, hal, &uuid);
555                 if (rc)
556                         GOTO(out_buf, rc);
557         }
558
559         /* Uses the ldlm reverse import; this rpc will be seen by
560          *  the ldlm_callback_handler. Note this sends a request RPC
561          * from a server (MDT) to a client (MDC), backwards of normal comms.
562          */
563         exp = cfs_hash_lookup(mdt2obd_dev(mdt)->obd_uuid_hash, &uuid);
564         if (exp == NULL || exp->exp_disconnected) {
565                 if (exp != NULL)
566                         class_export_put(exp);
567                 /* This should clean up agents on evicted exports */
568                 rc = -ENOENT;
569                 CERROR("%s: agent uuid (%s) not found, unregistering:"
570                        " rc = %d\n",
571                        mdt_obd_name(mdt), obd_uuid2str(&uuid), rc);
572                 mdt_hsm_agent_unregister(mti, &uuid);
573                 GOTO(out, rc);
574         }
575
576         /* send request to agent */
577         rc = do_set_info_async(exp->exp_imp_reverse, LDLM_SET_INFO,
578                                LUSTRE_OBD_VERSION,
579                                sizeof(KEY_HSM_COPYTOOL_SEND),
580                                KEY_HSM_COPYTOOL_SEND,
581                                kuc_len(len), kuc_ptr(buf), NULL);
582
583         if (rc)
584                 CERROR("%s: cannot send request to agent '%s': rc = %d\n",
585                        mdt_obd_name(mdt), obd_uuid2str(&uuid), rc);
586
587         class_export_put(exp);
588
589         if (rc == -EPIPE) {
590                 CDEBUG(D_HSM, "Lost connection to agent '%s', unregistering\n",
591                        obd_uuid2str(&uuid));
592                 mdt_hsm_agent_unregister(mti, &uuid);
593         }
594
595 out:
596         if (rc != 0 && is_registered) {
597                 /* in case of error, we have to unregister requests */
598                 hai = hai_first(hal);
599                 for (i = 0; i < hal->hal_count; i++, hai = hai_next(hai)) {
600                         if (hai->hai_action == HSMA_CANCEL)
601                                 continue;
602                         mdt_cdt_remove_request(cdt, hai->hai_cookie);
603                 }
604         }
605
606 out_buf:
607         kuc_free(buf, len);
608
609         RETURN(rc);
610 }
611
612 /**
613  * seq_file method called to start access to debugfs file
614  */
615 static void *mdt_hsm_agent_debugfs_start(struct seq_file *s, loff_t *off)
616 {
617         struct mdt_device       *mdt = s->private;
618         struct coordinator      *cdt = &mdt->mdt_coordinator;
619         struct list_head        *pos;
620         loff_t                   i;
621         ENTRY;
622
623         down_read(&cdt->cdt_agent_lock);
624
625         if (list_empty(&cdt->cdt_agents))
626                 RETURN(NULL);
627
628         if (*off == 0)
629                 RETURN(SEQ_START_TOKEN);
630
631         i = 0;
632         list_for_each(pos, &cdt->cdt_agents) {
633                 i++;
634                 if (i >= *off)
635                         RETURN(pos);
636         }
637
638         RETURN(NULL);
639 }
640
641 /**
642  * seq_file method called to get next item
643  * just returns NULL at eof
644  */
645 static void *mdt_hsm_agent_debugfs_next(struct seq_file *s, void *v, loff_t *p)
646 {
647         struct mdt_device       *mdt = s->private;
648         struct coordinator      *cdt = &mdt->mdt_coordinator;
649         struct list_head        *pos = v;
650         ENTRY;
651
652         if (pos == SEQ_START_TOKEN)
653                 pos = cdt->cdt_agents.next;
654         else
655                 pos = pos->next;
656
657         (*p)++;
658         if (pos != &cdt->cdt_agents)
659                 RETURN(pos);
660
661         RETURN(NULL);
662 }
663
664 /**
665  */
666 static int mdt_hsm_agent_debugfs_show(struct seq_file *s, void *v)
667 {
668         struct list_head        *pos = v;
669         struct hsm_agent        *ha;
670         int                      i;
671         ENTRY;
672
673         if (pos == SEQ_START_TOKEN)
674                 RETURN(0);
675
676         ha = list_entry(pos, struct hsm_agent, ha_list);
677         seq_printf(s, "uuid=%s archive_id=", ha->ha_uuid.uuid);
678         if (ha->ha_archive_cnt == 0) {
679                 seq_printf(s, "ANY");
680         } else {
681                 seq_printf(s, "%d", ha->ha_archive_id[0]);
682                 for (i = 1; i < ha->ha_archive_cnt; i++)
683                         seq_printf(s, ",%d", ha->ha_archive_id[i]);
684         }
685
686         seq_printf(s, " requests=[current:%d ok:%d errors:%d]\n",
687                    atomic_read(&ha->ha_requests),
688                    atomic_read(&ha->ha_success),
689                    atomic_read(&ha->ha_failure));
690         RETURN(0);
691 }
692
693 /**
694  * seq_file method called to stop access to debugfs file
695  */
696 static void mdt_hsm_agent_debugfs_stop(struct seq_file *s, void *v)
697 {
698         struct mdt_device       *mdt = s->private;
699         struct coordinator      *cdt = &mdt->mdt_coordinator;
700
701         up_read(&cdt->cdt_agent_lock);
702 }
703
704 /* hsm agent list debugfs functions */
705 static const struct seq_operations mdt_hsm_agent_debugfs_ops = {
706         .start  = mdt_hsm_agent_debugfs_start,
707         .next   = mdt_hsm_agent_debugfs_next,
708         .show   = mdt_hsm_agent_debugfs_show,
709         .stop   = mdt_hsm_agent_debugfs_stop,
710 };
711
712 /**
713  * public function called at open of debugfs file to get
714  * list of agents
715  */
716 static int ldebugfs_open_hsm_agent(struct inode *inode, struct file *file)
717 {
718         struct seq_file *s;
719         int              rc;
720         ENTRY;
721
722         rc = seq_open(file, &mdt_hsm_agent_debugfs_ops);
723         if (rc)
724                 RETURN(rc);
725
726         s = file->private_data;
727         s->private = inode->i_private;
728
729         RETURN(rc);
730 }
731
732 /* methods to access hsm agent list */
733 const struct file_operations mdt_hsm_agent_fops = {
734         .owner          = THIS_MODULE,
735         .open           = ldebugfs_open_hsm_agent,
736         .read           = seq_read,
737         .llseek         = seq_lseek,
738         .release        = seq_release,
739 };