]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - cmd/zpool/zpool_iter.c
Merge branch 'zfsonlinux/merge-spl'
[FreeBSD/FreeBSD.git] / cmd / zpool / zpool_iter.c
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25
26 /*
27  * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>.
28  */
29
30 #include <libintl.h>
31 #include <libuutil.h>
32 #include <stddef.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <strings.h>
36 #include <thread_pool.h>
37
38 #include <libzfs.h>
39 #include <sys/zfs_context.h>
40 #include <sys/wait.h>
41
42 #include "zpool_util.h"
43
44 /*
45  * Private interface for iterating over pools specified on the command line.
46  * Most consumers will call for_each_pool, but in order to support iostat, we
47  * allow fined grained control through the zpool_list_t interface.
48  */
49
50 typedef struct zpool_node {
51         zpool_handle_t  *zn_handle;
52         uu_avl_node_t   zn_avlnode;
53         int             zn_mark;
54 } zpool_node_t;
55
56 struct zpool_list {
57         boolean_t       zl_findall;
58         uu_avl_t        *zl_avl;
59         uu_avl_pool_t   *zl_pool;
60         zprop_list_t    **zl_proplist;
61 };
62
63 /* ARGSUSED */
64 static int
65 zpool_compare(const void *larg, const void *rarg, void *unused)
66 {
67         zpool_handle_t *l = ((zpool_node_t *)larg)->zn_handle;
68         zpool_handle_t *r = ((zpool_node_t *)rarg)->zn_handle;
69         const char *lname = zpool_get_name(l);
70         const char *rname = zpool_get_name(r);
71
72         return (strcmp(lname, rname));
73 }
74
75 /*
76  * Callback function for pool_list_get().  Adds the given pool to the AVL tree
77  * of known pools.
78  */
79 static int
80 add_pool(zpool_handle_t *zhp, void *data)
81 {
82         zpool_list_t *zlp = data;
83         zpool_node_t *node = safe_malloc(sizeof (zpool_node_t));
84         uu_avl_index_t idx;
85
86         node->zn_handle = zhp;
87         uu_avl_node_init(node, &node->zn_avlnode, zlp->zl_pool);
88         if (uu_avl_find(zlp->zl_avl, node, NULL, &idx) == NULL) {
89                 if (zlp->zl_proplist &&
90                     zpool_expand_proplist(zhp, zlp->zl_proplist) != 0) {
91                         zpool_close(zhp);
92                         free(node);
93                         return (-1);
94                 }
95                 uu_avl_insert(zlp->zl_avl, node, idx);
96         } else {
97                 zpool_close(zhp);
98                 free(node);
99                 return (-1);
100         }
101
102         return (0);
103 }
104
105 /*
106  * Create a list of pools based on the given arguments.  If we're given no
107  * arguments, then iterate over all pools in the system and add them to the AVL
108  * tree.  Otherwise, add only those pool explicitly specified on the command
109  * line.
110  */
111 zpool_list_t *
112 pool_list_get(int argc, char **argv, zprop_list_t **proplist, int *err)
113 {
114         zpool_list_t *zlp;
115
116         zlp = safe_malloc(sizeof (zpool_list_t));
117
118         zlp->zl_pool = uu_avl_pool_create("zfs_pool", sizeof (zpool_node_t),
119             offsetof(zpool_node_t, zn_avlnode), zpool_compare, UU_DEFAULT);
120
121         if (zlp->zl_pool == NULL)
122                 zpool_no_memory();
123
124         if ((zlp->zl_avl = uu_avl_create(zlp->zl_pool, NULL,
125             UU_DEFAULT)) == NULL)
126                 zpool_no_memory();
127
128         zlp->zl_proplist = proplist;
129
130         if (argc == 0) {
131                 (void) zpool_iter(g_zfs, add_pool, zlp);
132                 zlp->zl_findall = B_TRUE;
133         } else {
134                 int i;
135
136                 for (i = 0; i < argc; i++) {
137                         zpool_handle_t *zhp;
138
139                         if ((zhp = zpool_open_canfail(g_zfs, argv[i])) !=
140                             NULL) {
141                                 if (add_pool(zhp, zlp) != 0)
142                                         *err = B_TRUE;
143                         } else {
144                                 *err = B_TRUE;
145                         }
146                 }
147         }
148
149         return (zlp);
150 }
151
152 /*
153  * Search for any new pools, adding them to the list.  We only add pools when no
154  * options were given on the command line.  Otherwise, we keep the list fixed as
155  * those that were explicitly specified.
156  */
157 void
158 pool_list_update(zpool_list_t *zlp)
159 {
160         if (zlp->zl_findall)
161                 (void) zpool_iter(g_zfs, add_pool, zlp);
162 }
163
164 /*
165  * Iterate over all pools in the list, executing the callback for each
166  */
167 int
168 pool_list_iter(zpool_list_t *zlp, int unavail, zpool_iter_f func,
169     void *data)
170 {
171         zpool_node_t *node, *next_node;
172         int ret = 0;
173
174         for (node = uu_avl_first(zlp->zl_avl); node != NULL; node = next_node) {
175                 next_node = uu_avl_next(zlp->zl_avl, node);
176                 if (zpool_get_state(node->zn_handle) != POOL_STATE_UNAVAIL ||
177                     unavail)
178                         ret |= func(node->zn_handle, data);
179         }
180
181         return (ret);
182 }
183
184 /*
185  * Remove the given pool from the list.  When running iostat, we want to remove
186  * those pools that no longer exist.
187  */
188 void
189 pool_list_remove(zpool_list_t *zlp, zpool_handle_t *zhp)
190 {
191         zpool_node_t search, *node;
192
193         search.zn_handle = zhp;
194         if ((node = uu_avl_find(zlp->zl_avl, &search, NULL, NULL)) != NULL) {
195                 uu_avl_remove(zlp->zl_avl, node);
196                 zpool_close(node->zn_handle);
197                 free(node);
198         }
199 }
200
201 /*
202  * Free all the handles associated with this list.
203  */
204 void
205 pool_list_free(zpool_list_t *zlp)
206 {
207         uu_avl_walk_t *walk;
208         zpool_node_t *node;
209
210         if ((walk = uu_avl_walk_start(zlp->zl_avl, UU_WALK_ROBUST)) == NULL) {
211                 (void) fprintf(stderr,
212                     gettext("internal error: out of memory"));
213                 exit(1);
214         }
215
216         while ((node = uu_avl_walk_next(walk)) != NULL) {
217                 uu_avl_remove(zlp->zl_avl, node);
218                 zpool_close(node->zn_handle);
219                 free(node);
220         }
221
222         uu_avl_walk_end(walk);
223         uu_avl_destroy(zlp->zl_avl);
224         uu_avl_pool_destroy(zlp->zl_pool);
225
226         free(zlp);
227 }
228
229 /*
230  * Returns the number of elements in the pool list.
231  */
232 int
233 pool_list_count(zpool_list_t *zlp)
234 {
235         return (uu_avl_numnodes(zlp->zl_avl));
236 }
237
238 /*
239  * High level function which iterates over all pools given on the command line,
240  * using the pool_list_* interfaces.
241  */
242 int
243 for_each_pool(int argc, char **argv, boolean_t unavail,
244     zprop_list_t **proplist, zpool_iter_f func, void *data)
245 {
246         zpool_list_t *list;
247         int ret = 0;
248
249         if ((list = pool_list_get(argc, argv, proplist, &ret)) == NULL)
250                 return (1);
251
252         if (pool_list_iter(list, unavail, func, data) != 0)
253                 ret = 1;
254
255         pool_list_free(list);
256
257         return (ret);
258 }
259
260 static int
261 for_each_vdev_cb(zpool_handle_t *zhp, nvlist_t *nv, pool_vdev_iter_f func,
262     void *data)
263 {
264         nvlist_t **child;
265         uint_t c, children;
266         int ret = 0;
267         int i;
268         char *type;
269
270         const char *list[] = {
271             ZPOOL_CONFIG_SPARES,
272             ZPOOL_CONFIG_L2CACHE,
273             ZPOOL_CONFIG_CHILDREN
274         };
275
276         for (i = 0; i < ARRAY_SIZE(list); i++) {
277                 if (nvlist_lookup_nvlist_array(nv, list[i], &child,
278                     &children) == 0) {
279                         for (c = 0; c < children; c++) {
280                                 uint64_t ishole = 0;
281
282                                 (void) nvlist_lookup_uint64(child[c],
283                                     ZPOOL_CONFIG_IS_HOLE, &ishole);
284
285                                 if (ishole)
286                                         continue;
287
288                                 ret |= for_each_vdev_cb(zhp, child[c], func,
289                                     data);
290                         }
291                 }
292         }
293
294         if (nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) != 0)
295                 return (ret);
296
297         /* Don't run our function on root vdevs */
298         if (strcmp(type, VDEV_TYPE_ROOT) != 0) {
299                 ret |= func(zhp, nv, data);
300         }
301
302         return (ret);
303 }
304
305 /*
306  * This is the equivalent of for_each_pool() for vdevs.  It iterates thorough
307  * all vdevs in the pool, ignoring root vdevs and holes, calling func() on
308  * each one.
309  *
310  * @zhp:        Zpool handle
311  * @func:       Function to call on each vdev
312  * @data:       Custom data to pass to the function
313  */
314 int
315 for_each_vdev(zpool_handle_t *zhp, pool_vdev_iter_f func, void *data)
316 {
317         nvlist_t *config, *nvroot = NULL;
318
319         if ((config = zpool_get_config(zhp, NULL)) != NULL) {
320                 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
321                     &nvroot) == 0);
322         }
323         return (for_each_vdev_cb(zhp, nvroot, func, data));
324 }
325
326 /*
327  * Process the vcdl->vdev_cmd_data[] array to figure out all the unique column
328  * names and their widths.  When this function is done, vcdl->uniq_cols,
329  * vcdl->uniq_cols_cnt, and vcdl->uniq_cols_width will be filled in.
330  */
331 static void
332 process_unique_cmd_columns(vdev_cmd_data_list_t *vcdl)
333 {
334         char **uniq_cols = NULL, **tmp = NULL;
335         int *uniq_cols_width;
336         vdev_cmd_data_t *data;
337         int cnt = 0;
338         int k;
339
340         /* For each vdev */
341         for (int i = 0; i < vcdl->count; i++) {
342                 data = &vcdl->data[i];
343                 /* For each column the vdev reported */
344                 for (int j = 0; j < data->cols_cnt; j++) {
345                         /* Is this column in our list of unique column names? */
346                         for (k = 0; k < cnt; k++) {
347                                 if (strcmp(data->cols[j], uniq_cols[k]) == 0)
348                                         break; /* yes it is */
349                         }
350                         if (k == cnt) {
351                                 /* No entry for column, add to list */
352                                 tmp = realloc(uniq_cols, sizeof (*uniq_cols) *
353                                     (cnt + 1));
354                                 if (tmp == NULL)
355                                         break; /* Nothing we can do... */
356                                 uniq_cols = tmp;
357                                 uniq_cols[cnt] = data->cols[j];
358                                 cnt++;
359                         }
360                 }
361         }
362
363         /*
364          * We now have a list of all the unique column names.  Figure out the
365          * max width of each column by looking at the column name and all its
366          * values.
367          */
368         uniq_cols_width = safe_malloc(sizeof (*uniq_cols_width) * cnt);
369         for (int i = 0; i < cnt; i++) {
370                 /* Start off with the column title's width */
371                 uniq_cols_width[i] = strlen(uniq_cols[i]);
372                 /* For each vdev */
373                 for (int j = 0; j < vcdl->count; j++) {
374                         /* For each of the vdev's values in a column */
375                         data = &vcdl->data[j];
376                         for (k = 0; k < data->cols_cnt; k++) {
377                                 /* Does this vdev have a value for this col? */
378                                 if (strcmp(data->cols[k], uniq_cols[i]) == 0) {
379                                         /* Is the value width larger? */
380                                         uniq_cols_width[i] =
381                                             MAX(uniq_cols_width[i],
382                                             strlen(data->lines[k]));
383                                 }
384                         }
385                 }
386         }
387
388         vcdl->uniq_cols = uniq_cols;
389         vcdl->uniq_cols_cnt = cnt;
390         vcdl->uniq_cols_width = uniq_cols_width;
391 }
392
393
394 /*
395  * Process a line of command output
396  *
397  * When running 'zpool iostat|status -c' the lines of output can either be
398  * in the form of:
399  *
400  *      column_name=value
401  *
402  * Or just:
403  *
404  *      value
405  *
406  * Process the column_name (if any) and value.
407  *
408  * Returns 0 if line was processed, and there are more lines can still be
409  * processed.
410  *
411  * Returns 1 if this was the last line to process, or error.
412  */
413 static int
414 vdev_process_cmd_output(vdev_cmd_data_t *data, char *line)
415 {
416         char *col = NULL;
417         char *val = line;
418         char *equals;
419         char **tmp;
420
421         if (line == NULL)
422                 return (1);
423
424         equals = strchr(line, '=');
425         if (equals != NULL) {
426                 /*
427                  * We have a 'column=value' type line.  Split it into the
428                  * column and value strings by turning the '=' into a '\0'.
429                  */
430                 *equals = '\0';
431                 col = line;
432                 val = equals + 1;
433         } else {
434                 val = line;
435         }
436
437         /* Do we already have a column by this name?  If so, skip it. */
438         if (col != NULL) {
439                 for (int i = 0; i < data->cols_cnt; i++) {
440                         if (strcmp(col, data->cols[i]) == 0)
441                                 return (0); /* Duplicate, skip */
442                 }
443         }
444
445         if (val != NULL) {
446                 tmp = realloc(data->lines,
447                     (data->lines_cnt + 1) * sizeof (*data->lines));
448                 if (tmp == NULL)
449                         return (1);
450
451                 data->lines = tmp;
452                 data->lines[data->lines_cnt] = strdup(val);
453                 data->lines_cnt++;
454         }
455
456         if (col != NULL) {
457                 tmp = realloc(data->cols,
458                     (data->cols_cnt + 1) * sizeof (*data->cols));
459                 if (tmp == NULL)
460                         return (1);
461
462                 data->cols = tmp;
463                 data->cols[data->cols_cnt] = strdup(col);
464                 data->cols_cnt++;
465         }
466
467         if (val != NULL && col == NULL)
468                 return (1);
469
470         return (0);
471 }
472
473 /*
474  * Run the cmd and store results in *data.
475  */
476 static void
477 vdev_run_cmd(vdev_cmd_data_t *data, char *cmd)
478 {
479         int rc;
480         char *argv[2] = {cmd, 0};
481         char *env[5] = {"PATH=/bin:/sbin:/usr/bin:/usr/sbin", NULL, NULL, NULL,
482             NULL};
483         char **lines = NULL;
484         int lines_cnt = 0;
485         int i;
486
487         /* Setup our custom environment variables */
488         rc = asprintf(&env[1], "VDEV_PATH=%s",
489             data->path ? data->path : "");
490         if (rc == -1)
491                 goto out;
492
493         rc = asprintf(&env[2], "VDEV_UPATH=%s",
494             data->upath ? data->upath : "");
495         if (rc == -1)
496                 goto out;
497
498         rc = asprintf(&env[3], "VDEV_ENC_SYSFS_PATH=%s",
499             data->vdev_enc_sysfs_path ?
500             data->vdev_enc_sysfs_path : "");
501         if (rc == -1)
502                 goto out;
503
504         /* Run the command */
505         rc = libzfs_run_process_get_stdout_nopath(cmd, argv, env, &lines,
506             &lines_cnt);
507         if (rc != 0)
508                 goto out;
509
510         /* Process the output we got */
511         for (i = 0; i < lines_cnt; i++)
512                 if (vdev_process_cmd_output(data, lines[i]) != 0)
513                         break;
514
515 out:
516         if (lines != NULL)
517                 libzfs_free_str_array(lines, lines_cnt);
518
519         /* Start with i = 1 since env[0] was statically allocated */
520         for (i = 1; i < ARRAY_SIZE(env); i++)
521                 if (env[i] != NULL)
522                         free(env[i]);
523 }
524
525 /*
526  * Generate the search path for zpool iostat/status -c scripts.
527  * The string returned must be freed.
528  */
529 char *
530 zpool_get_cmd_search_path(void)
531 {
532         const char *env;
533         char *sp = NULL;
534
535         env = getenv("ZPOOL_SCRIPTS_PATH");
536         if (env != NULL)
537                 return (strdup(env));
538
539         env = getenv("HOME");
540         if (env != NULL) {
541                 if (asprintf(&sp, "%s/.zpool.d:%s",
542                     env, ZPOOL_SCRIPTS_DIR) != -1) {
543                         return (sp);
544                 }
545         }
546
547         if (asprintf(&sp, "%s", ZPOOL_SCRIPTS_DIR) != -1)
548                 return (sp);
549
550         return (NULL);
551 }
552
553 /* Thread function run for each vdev */
554 static void
555 vdev_run_cmd_thread(void *cb_cmd_data)
556 {
557         vdev_cmd_data_t *data = cb_cmd_data;
558         char *cmd = NULL, *cmddup, *cmdrest;
559
560         cmddup = strdup(data->cmd);
561         if (cmddup == NULL)
562                 return;
563
564         cmdrest = cmddup;
565         while ((cmd = strtok_r(cmdrest, ",", &cmdrest))) {
566                 char *dir = NULL, *sp, *sprest;
567                 char fullpath[MAXPATHLEN];
568
569                 if (strchr(cmd, '/') != NULL)
570                         continue;
571
572                 sp = zpool_get_cmd_search_path();
573                 if (sp == NULL)
574                         continue;
575
576                 sprest = sp;
577                 while ((dir = strtok_r(sprest, ":", &sprest))) {
578                         if (snprintf(fullpath, sizeof (fullpath),
579                             "%s/%s", dir, cmd) == -1)
580                                 continue;
581
582                         if (access(fullpath, X_OK) == 0) {
583                                 vdev_run_cmd(data, fullpath);
584                                 break;
585                         }
586                 }
587                 free(sp);
588         }
589         free(cmddup);
590 }
591
592 /* For each vdev in the pool run a command */
593 static int
594 for_each_vdev_run_cb(zpool_handle_t *zhp, nvlist_t *nv, void *cb_vcdl)
595 {
596         vdev_cmd_data_list_t *vcdl = cb_vcdl;
597         vdev_cmd_data_t *data;
598         char *path = NULL;
599         char *vname = NULL;
600         char *vdev_enc_sysfs_path = NULL;
601         int i, match = 0;
602
603         if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) != 0)
604                 return (1);
605
606         nvlist_lookup_string(nv, ZPOOL_CONFIG_VDEV_ENC_SYSFS_PATH,
607             &vdev_enc_sysfs_path);
608
609         /* Spares show more than once if they're in use, so skip if exists */
610         for (i = 0; i < vcdl->count; i++) {
611                 if ((strcmp(vcdl->data[i].path, path) == 0) &&
612                     (strcmp(vcdl->data[i].pool, zpool_get_name(zhp)) == 0)) {
613                         /* vdev already exists, skip it */
614                         return (0);
615                 }
616         }
617
618         /* Check for whitelisted vdevs here, if any */
619         for (i = 0; i < vcdl->vdev_names_count; i++) {
620                 vname = zpool_vdev_name(g_zfs, zhp, nv, vcdl->cb_name_flags);
621                 if (strcmp(vcdl->vdev_names[i], vname) == 0) {
622                         free(vname);
623                         match = 1;
624                         break; /* match */
625                 }
626                 free(vname);
627         }
628
629         /* If we whitelisted vdevs, and this isn't one of them, then bail out */
630         if (!match && vcdl->vdev_names_count)
631                 return (0);
632
633         /*
634          * Resize our array and add in the new element.
635          */
636         if (!(vcdl->data = realloc(vcdl->data,
637             sizeof (*vcdl->data) * (vcdl->count + 1))))
638                 return (ENOMEM);        /* couldn't realloc */
639
640         data = &vcdl->data[vcdl->count];
641
642         data->pool = strdup(zpool_get_name(zhp));
643         data->path = strdup(path);
644         data->upath = zfs_get_underlying_path(path);
645         data->cmd = vcdl->cmd;
646         data->lines = data->cols = NULL;
647         data->lines_cnt = data->cols_cnt = 0;
648         if (vdev_enc_sysfs_path)
649                 data->vdev_enc_sysfs_path = strdup(vdev_enc_sysfs_path);
650         else
651                 data->vdev_enc_sysfs_path = NULL;
652
653         vcdl->count++;
654
655         return (0);
656 }
657
658 /* Get the names and count of the vdevs */
659 static int
660 all_pools_for_each_vdev_gather_cb(zpool_handle_t *zhp, void *cb_vcdl)
661 {
662         return (for_each_vdev(zhp, for_each_vdev_run_cb, cb_vcdl));
663 }
664
665 /*
666  * Now that vcdl is populated with our complete list of vdevs, spawn
667  * off the commands.
668  */
669 static void
670 all_pools_for_each_vdev_run_vcdl(vdev_cmd_data_list_t *vcdl)
671 {
672         tpool_t *t;
673
674         t = tpool_create(1, 5 * sysconf(_SC_NPROCESSORS_ONLN), 0, NULL);
675         if (t == NULL)
676                 return;
677
678         /* Spawn off the command for each vdev */
679         for (int i = 0; i < vcdl->count; i++) {
680                 (void) tpool_dispatch(t, vdev_run_cmd_thread,
681                     (void *) &vcdl->data[i]);
682         }
683
684         /* Wait for threads to finish */
685         tpool_wait(t);
686         tpool_destroy(t);
687 }
688
689 /*
690  * Run command 'cmd' on all vdevs in all pools in argv.  Saves the first line of
691  * output from the command in vcdk->data[].line for all vdevs.  If you want
692  * to run the command on only certain vdevs, fill in g_zfs, vdev_names,
693  * vdev_names_count, and cb_name_flags.  Otherwise leave them as zero.
694  *
695  * Returns a vdev_cmd_data_list_t that must be freed with
696  * free_vdev_cmd_data_list();
697  */
698 vdev_cmd_data_list_t *
699 all_pools_for_each_vdev_run(int argc, char **argv, char *cmd,
700     libzfs_handle_t *g_zfs, char **vdev_names, int vdev_names_count,
701     int cb_name_flags)
702 {
703         vdev_cmd_data_list_t *vcdl;
704         vcdl = safe_malloc(sizeof (vdev_cmd_data_list_t));
705         vcdl->cmd = cmd;
706
707         vcdl->vdev_names = vdev_names;
708         vcdl->vdev_names_count = vdev_names_count;
709         vcdl->cb_name_flags = cb_name_flags;
710         vcdl->g_zfs = g_zfs;
711
712         /* Gather our list of all vdevs in all pools */
713         for_each_pool(argc, argv, B_TRUE, NULL,
714             all_pools_for_each_vdev_gather_cb, vcdl);
715
716         /* Run command on all vdevs in all pools */
717         all_pools_for_each_vdev_run_vcdl(vcdl);
718
719         /*
720          * vcdl->data[] now contains all the column names and values for each
721          * vdev.  We need to process that into a master list of unique column
722          * names, and figure out the width of each column.
723          */
724         process_unique_cmd_columns(vcdl);
725
726         return (vcdl);
727 }
728
729 /*
730  * Free the vdev_cmd_data_list_t created by all_pools_for_each_vdev_run()
731  */
732 void
733 free_vdev_cmd_data_list(vdev_cmd_data_list_t *vcdl)
734 {
735         free(vcdl->uniq_cols);
736         free(vcdl->uniq_cols_width);
737
738         for (int i = 0; i < vcdl->count; i++) {
739                 free(vcdl->data[i].path);
740                 free(vcdl->data[i].pool);
741                 free(vcdl->data[i].upath);
742
743                 for (int j = 0; j < vcdl->data[i].lines_cnt; j++)
744                         free(vcdl->data[i].lines[j]);
745
746                 free(vcdl->data[i].lines);
747
748                 for (int j = 0; j < vcdl->data[i].cols_cnt; j++)
749                         free(vcdl->data[i].cols[j]);
750
751                 free(vcdl->data[i].cols);
752                 free(vcdl->data[i].vdev_enc_sysfs_path);
753         }
754         free(vcdl->data);
755         free(vcdl);
756 }