Whamcloud - gitweb
LU-17343 utils: added --path option for lctl list_param
[fs/lustre-release.git] / lustre / utils / lctl_thread.h
1 /*
2  * LGPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * (C) Copyright 2012 Commissariat a l'energie atomique et aux energies
7  *     alternatives
8  *
9  * Copyright (c) 2016, 2017, Intel Corporation.
10  *
11  * All rights reserved. This program and the accompanying materials
12  * are made available under the terms of the GNU Lesser General Public License
13  * (LGPL) version 2.1 or (at your discretion) any later version.
14  * (LGPL) version 2.1 accompanies this distribution, and is available at
15  * http://www.gnu.org/licenses/lgpl-2.1.html
16  *
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * Lesser General Public License for more details.
22  *
23  * LGPL HEADER END
24  */
25 /*
26  *
27  * lustre/utils/lctl_thread.h
28  *
29  * Author: Rajeev Mishra <rajeevm@hpe.com>
30  */
31 #if HAVE_LIBPTHREAD
32 #include <pthread.h>
33 #endif
34 #ifndef STRINGIFY
35 #define STRINGIFY(a) #a
36 #endif
37
38 struct param_opts {
39         unsigned int po_only_name:1;
40         unsigned int po_show_name:1;
41         unsigned int po_only_pathname:1;
42         unsigned int po_show_type:1;
43         unsigned int po_recursive:1;
44         unsigned int po_perm:1;
45         unsigned int po_delete:1;
46         unsigned int po_only_dir:1;
47         unsigned int po_file:1;
48         unsigned int po_yaml:1;
49         unsigned int po_detail:1;
50         unsigned int po_header:1;
51         unsigned int po_parallel_threads;
52 };
53
54 #ifdef HAVE_LIBPTHREAD
55 #define popt_is_parallel(popt) ((popt).po_parallel_threads > 0)
56
57 int write_param(const char *path, const char *param_name,
58                 struct param_opts *popt, const char *value);
59
60 #define LCFG_THREADS_DEF 8
61
62 /* A work item for parallel set_param */
63 struct sp_work_item {
64         /* The full path to the parameter file */
65         char *spwi_path;
66
67         /* The parameter name as returned by display_name */
68         char *spwi_param_name;
69
70         /* The value to which the parameter is to be set */
71         char *spwi_value;
72 };
73
74 /* A work queue struct for parallel set_param */
75 struct sp_workq {
76         /* The parameter options passed to set_param */
77         struct param_opts *spwq_popt;
78
79         /* The number of valid items in spwq_items */
80         int spwq_len;
81
82         /* The size of the spwq_items list */
83         int spwq_size;
84
85         /* The current index into the spwq_items list */
86         int spwq_cur_index;
87
88         /* Array of work items. */
89         struct sp_work_item *spwq_items;
90
91         /* A mutex to control access to the work queue */
92         pthread_mutex_t spwq_mutex;
93 };
94
95 int spwq_init(struct sp_workq *wq, struct param_opts *popt);
96 int spwq_destroy(struct sp_workq *wq);
97 int spwq_expand(struct sp_workq *wq, size_t num_items);
98 int spwq_add_item(struct sp_workq *wq, char *path, char *param_name,
99                   char *value);
100 int sp_run_threads(struct sp_workq *wq);
101 #else
102 #define popt_is_parallel(popt) 0
103
104 struct sp_workq { int unused; };
105
106 static inline int spwq_init(struct sp_workq *wq, struct param_opts *popt)
107 { return 0; }
108 static inline int spwq_destroy(struct sp_workq *wq)
109 { return 0; }
110 static inline int spwq_expand(struct sp_workq *wq, size_t num_items)
111 { return 0; }
112 static inline int spwq_add_item(struct sp_workq *wq, char *path,
113                                 char *param_name, char *value)
114 { return 0; }
115 static inline int sp_run_threads(struct sp_workq *wq)
116 { return 0; }
117
118 #endif