Print this page
5847 libzfs_diff should check zfs_prop_get() return


   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 /*
  23  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.

  24  */
  25 
  26 /*
  27  * zfs diff support
  28  */
  29 #include <ctype.h>
  30 #include <errno.h>
  31 #include <libintl.h>
  32 #include <string.h>
  33 #include <sys/types.h>
  34 #include <sys/stat.h>
  35 #include <fcntl.h>
  36 #include <attr.h>
  37 #include <stddef.h>
  38 #include <unistd.h>
  39 #include <stdio.h>
  40 #include <stdlib.h>
  41 #include <stropts.h>
  42 #include <pthread.h>
  43 #include <sys/zfs_ioctl.h>


 599 
 600         if (fsnlen <= 1 || tsnlen == 1 || (fdslen == 0 && tdslen == 0) ||
 601             (fsnlen == 0 && tsnlen == 0)) {
 602                 return (zfs_error(hdl, EZFS_INVALIDNAME, di->errbuf));
 603         } else if ((fdslen > 0 && tdslen > 0) &&
 604             ((tdslen != fdslen || strncmp(fromsnap, tosnap, fdslen) != 0))) {
 605                 /*
 606                  * not the same dataset name, might be okay if
 607                  * tosnap is a clone of a fromsnap descendant.
 608                  */
 609                 char origin[ZFS_MAXNAMELEN];
 610                 zprop_source_t src;
 611                 zfs_handle_t *zhp;
 612 
 613                 di->ds = zfs_alloc(di->zhp->zfs_hdl, tdslen + 1);
 614                 (void) strncpy(di->ds, tosnap, tdslen);
 615                 di->ds[tdslen] = '\0';
 616 
 617                 zhp = zfs_open(hdl, di->ds, ZFS_TYPE_FILESYSTEM);
 618                 while (zhp != NULL) {
 619                         (void) zfs_prop_get(zhp, ZFS_PROP_ORIGIN,
 620                             origin, sizeof (origin), &src, NULL, 0, B_FALSE);
 621 



 622                         if (strncmp(origin, fromsnap, fsnlen) == 0)
 623                                 break;
 624 
 625                         (void) zfs_close(zhp);
 626                         zhp = zfs_open(hdl, origin, ZFS_TYPE_FILESYSTEM);
 627                 }
 628 
 629                 if (zhp == NULL) {
 630                         (void) snprintf(di->errbuf, sizeof (di->errbuf),
 631                             dgettext(TEXT_DOMAIN,
 632                             "Not an earlier snapshot from the same fs"));
 633                         return (zfs_error(hdl, EZFS_INVALIDNAME, di->errbuf));
 634                 } else {
 635                         (void) zfs_close(zhp);
 636                 }
 637 
 638                 di->isclone = B_TRUE;
 639                 di->fromsnap = zfs_strdup(hdl, fromsnap);
 640                 if (tsnlen) {
 641                         di->tosnap = zfs_strdup(hdl, tosnap);




   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 /*
  23  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
  25  */
  26 
  27 /*
  28  * zfs diff support
  29  */
  30 #include <ctype.h>
  31 #include <errno.h>
  32 #include <libintl.h>
  33 #include <string.h>
  34 #include <sys/types.h>
  35 #include <sys/stat.h>
  36 #include <fcntl.h>
  37 #include <attr.h>
  38 #include <stddef.h>
  39 #include <unistd.h>
  40 #include <stdio.h>
  41 #include <stdlib.h>
  42 #include <stropts.h>
  43 #include <pthread.h>
  44 #include <sys/zfs_ioctl.h>


 600 
 601         if (fsnlen <= 1 || tsnlen == 1 || (fdslen == 0 && tdslen == 0) ||
 602             (fsnlen == 0 && tsnlen == 0)) {
 603                 return (zfs_error(hdl, EZFS_INVALIDNAME, di->errbuf));
 604         } else if ((fdslen > 0 && tdslen > 0) &&
 605             ((tdslen != fdslen || strncmp(fromsnap, tosnap, fdslen) != 0))) {
 606                 /*
 607                  * not the same dataset name, might be okay if
 608                  * tosnap is a clone of a fromsnap descendant.
 609                  */
 610                 char origin[ZFS_MAXNAMELEN];
 611                 zprop_source_t src;
 612                 zfs_handle_t *zhp;
 613 
 614                 di->ds = zfs_alloc(di->zhp->zfs_hdl, tdslen + 1);
 615                 (void) strncpy(di->ds, tosnap, tdslen);
 616                 di->ds[tdslen] = '\0';
 617 
 618                 zhp = zfs_open(hdl, di->ds, ZFS_TYPE_FILESYSTEM);
 619                 while (zhp != NULL) {
 620                         if (zfs_prop_get(zhp, ZFS_PROP_ORIGIN, origin,
 621                             sizeof (origin), &src, NULL, 0, B_FALSE) != 0) {
 622                                 (void) zfs_close(zhp);
 623                                 zhp = NULL;
 624                                 break;
 625                         }
 626                         if (strncmp(origin, fromsnap, fsnlen) == 0)
 627                                 break;
 628 
 629                         (void) zfs_close(zhp);
 630                         zhp = zfs_open(hdl, origin, ZFS_TYPE_FILESYSTEM);
 631                 }
 632 
 633                 if (zhp == NULL) {
 634                         (void) snprintf(di->errbuf, sizeof (di->errbuf),
 635                             dgettext(TEXT_DOMAIN,
 636                             "Not an earlier snapshot from the same fs"));
 637                         return (zfs_error(hdl, EZFS_INVALIDNAME, di->errbuf));
 638                 } else {
 639                         (void) zfs_close(zhp);
 640                 }
 641 
 642                 di->isclone = B_TRUE;
 643                 di->fromsnap = zfs_strdup(hdl, fromsnap);
 644                 if (tsnlen) {
 645                         di->tosnap = zfs_strdup(hdl, tosnap);