Print this page
    
NEX-9532 NDMP: readdir errors when file/directory has special characters
Reviewed by: Peer Dampmann <peer.dampmann@nexenta.com>
Reviewed by: Alexander Eremin <alexander.eremin@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-5801 Snapshots left over after failed backups
Reviewed by: Rick Mesta <rick.mesta@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Revert "NEX-5801 Snapshots left over after failed backups"
This reverts commit f182fb95f09036db71fbfc6f0a6b90469b761f21.
NEX-5801 Snapshots left over after failed backups
Reviewed by: Rick Mesta <rick.mesta@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-2911 NDMP logging should use syslog and is too chatty
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/cmd/ndmpd/ndmp/ndmpd_scsi.c
          +++ new/usr/src/cmd/ndmpd/ndmp/ndmpd_scsi.c
   1    1  /*
   2    2   * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
   3    3   * Use is subject to license terms.
   4    4   */
   5    5  
   6    6  /*
   7    7   * BSD 3 Clause License
   8    8   *
   9    9   * Copyright (c) 2007, The Storage Networking Industry Association.
  10   10   *
  11   11   * Redistribution and use in source and binary forms, with or without
  12   12   * modification, are permitted provided that the following conditions
  13   13   * are met:
  14   14   *      - Redistributions of source code must retain the above copyright
  15   15   *        notice, this list of conditions and the following disclaimer.
  16   16   *
  17   17   *      - Redistributions in binary form must reproduce the above copyright
  18   18   *        notice, this list of conditions and the following disclaimer in
  19   19   *        the documentation and/or other materials provided with the
  20   20   *        distribution.
  21   21   *
  22   22   *      - Neither the name of The Storage Networking Industry Association (SNIA)
  23   23   *        nor the names of its contributors may be used to endorse or promote
  24   24   *        products derived from this software without specific prior written
  25   25   *        permission.
  26   26   *
  27   27   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28   28   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29   29   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30   30   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  
    | 
      ↓ open down ↓ | 
    30 lines elided | 
    
      ↑ open up ↑ | 
  
  31   31   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32   32   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  33   33   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  34   34   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  35   35   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  36   36   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37   37   * POSSIBILITY OF SUCH DAMAGE.
  38   38   */
  39   39  /* Copyright (c) 2007, The Storage Networking Industry Association. */
  40   40  /* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
       41 +/* Copyright 2017 Nexenta Systems, Inc. All rights reserved. */
  41   42  
  42   43  #include <sys/types.h>
       44 +#include <syslog.h>
  43   45  #include <ctype.h>
  44   46  #include <errno.h>
  45   47  #include <fcntl.h>
  46   48  #include <stdlib.h>
  47   49  #include "ndmpd_common.h"
  48   50  #include "ndmpd.h"
  49   51  #include <string.h>
  50   52  #include <sys/scsi/impl/uscsi.h>
  51   53  #include <sys/scsi/scsi.h>
  52   54  
  53   55  static void scsi_open_send_reply(ndmp_connection_t *connection, int err);
  54   56  static void common_open(ndmp_connection_t *connection, char *devname);
  55   57  static void common_set_target(ndmp_connection_t *connection, char *device,
  56   58      ushort_t controller, ushort_t sid, ushort_t lun);
  57   59  
  58   60  
  59   61  /*
  60   62   * ************************************************************************
  61   63   * NDMP V2 HANDLERS
  62   64   * ************************************************************************
  63   65   */
  64   66  
  65   67  /*
  66   68   * ndmpd_scsi_open_v2
  67   69   *
  68   70   * This handler opens the specified SCSI device.
  69   71   *
  70   72   * Parameters:
  71   73   *   connection (input) - connection handle.
  72   74   *   body       (input) - request message body.
  73   75   *
  74   76   * Returns:
  75   77   *   void
  76   78   */
  77   79  void
  78   80  ndmpd_scsi_open_v2(ndmp_connection_t *connection, void *body)
  79   81  {
  80   82          ndmp_scsi_open_request_v2 *request = (ndmp_scsi_open_request_v2 *)body;
  81   83  
  82   84          common_open(connection, request->device.name);
  83   85  }
  84   86  
  85   87  
  86   88  /*
  87   89   * ndmpd_scsi_close_v2
  88   90   *
  89   91   * This handler closes the currently open SCSI device.
  90   92   *
  91   93   * Parameters:
  92   94   *   connection (input) - connection handle.
  93   95   *   body       (input) - request message body.
  94   96   *
  95   97   * Returns:
  
    | 
      ↓ open down ↓ | 
    43 lines elided | 
    
      ↑ open up ↑ | 
  
  96   98   *   void
  97   99   */
  98  100  /*ARGSUSED*/
  99  101  void
 100  102  ndmpd_scsi_close_v2(ndmp_connection_t *connection, void *body)
 101  103  {
 102  104          ndmp_scsi_close_reply reply;
 103  105          ndmpd_session_t *session = ndmp_get_client_data(connection);
 104  106  
 105  107          if (session->ns_scsi.sd_is_open == -1) {
 106      -                NDMP_LOG(LOG_ERR, "SCSI device is not open.");
      108 +                syslog(LOG_ERR, "SCSI device is not open.");
 107  109                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 108  110                  ndmp_send_reply(connection, (void *) &reply,
 109  111                      "sending scsi_close reply");
 110  112                  return;
 111  113          }
 112  114          (void) ndmp_open_list_del(session->ns_scsi.sd_adapter_name,
 113  115              session->ns_scsi.sd_sid,
 114  116              session->ns_scsi.sd_lun);
 115  117          (void) close(session->ns_scsi.sd_devid);
 116  118  
 117  119          session->ns_scsi.sd_is_open = -1;
 118  120          session->ns_scsi.sd_devid = -1;
 119  121          session->ns_scsi.sd_sid = 0;
 120  122          session->ns_scsi.sd_lun = 0;
 121  123          session->ns_scsi.sd_valid_target_set = FALSE;
 122  124          (void) memset(session->ns_scsi.sd_adapter_name, 0,
 123  125              sizeof (session->ns_scsi.sd_adapter_name));
 124  126  
 125  127          reply.error = NDMP_NO_ERR;
 126  128          ndmp_send_reply(connection, (void *) &reply,
 127  129              "sending scsi_close reply");
 128  130  }
 129  131  
 130  132  
 131  133  /*
 132  134   * ndmpd_scsi_get_state_v2
 133  135   *
 134  136   * This handler returns state information for the currently open SCSI device.
 135  137   * Since the implementation only supports the opening of a specific SCSI
 136  138   * device, as opposed to a device that can talk to multiple SCSI targets,
 137  139   * this request is not supported. This request is only appropriate for
 138  140   * implementations that support device files that can target multiple
 139  141   * SCSI devices.
 140  142   *
 141  143   * Parameters:
 142  144   *   connection (input) - connection handle.
 143  145   *   body       (input) - request message body.
 144  146   *
 145  147   * Returns:
 146  148   *   void
 147  149   */
 148  150  /*ARGSUSED*/
 149  151  void
 150  152  ndmpd_scsi_get_state_v2(ndmp_connection_t *connection, void *body)
 151  153  {
 152  154          ndmp_scsi_get_state_reply reply;
 153  155          ndmpd_session_t *session = ndmp_get_client_data(connection);
 154  156  
 155  157          if (session->ns_scsi.sd_is_open == -1)
 156  158                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 157  159          else if (!session->ns_scsi.sd_valid_target_set) {
 158  160                  reply.error = NDMP_NO_ERR;
 159  161                  reply.target_controller = -1;
 160  162                  reply.target_id = -1;
 161  163                  reply.target_lun = -1;
 162  164          } else {
 163  165                  reply.error = NDMP_NO_ERR;
 164  166                  reply.target_controller = 0;
 165  167                  reply.target_id = session->ns_scsi.sd_sid;
 166  168                  reply.target_lun = session->ns_scsi.sd_lun;
 167  169          }
 168  170  
 169  171          ndmp_send_reply(connection, (void *) &reply,
 170  172              "sending scsi_get_state reply");
 171  173  }
 172  174  
 173  175  
 174  176  /*
 175  177   * ndmpd_scsi_set_target_v2
 176  178   *
 177  179   * This handler sets the SCSI target of the SCSI device.
 178  180   * It is only valid to use this request if the opened SCSI device
 179  181   * is capable of talking to multiple SCSI targets.
 180  182   * Since the implementation only supports the opening of a specific SCSI
 181  183   * device, as opposed to a device that can talk to multiple SCSI targets,
 182  184   * this request is not supported. This request is only appropriate for
 183  185   * implementations that support device files that can target multiple
 184  186   * SCSI devices.
 185  187   *
 186  188   * Parameters:
 187  189   *   connection (input) - connection handle.
 188  190   *   body       (input) - request message body.
 189  191   *
 190  192   * Returns:
 191  193   *   void
 192  194   */
 193  195  void
 194  196  ndmpd_scsi_set_target_v2(ndmp_connection_t *connection, void *body)
 195  197  {
 196  198          ndmp_scsi_set_target_request_v2 *request;
 197  199  
 198  200          request = (ndmp_scsi_set_target_request_v2 *) body;
 199  201  
 200  202          common_set_target(connection, request->device.name,
 201  203              request->target_controller, request->target_id,
 202  204              request->target_lun);
 203  205  }
 204  206  
 205  207  
 206  208  /*
 207  209   * ndmpd_scsi_reset_device_v2
 208  210   *
 209  211   * This handler resets the currently targeted SCSI device.
 210  212   *
 211  213   * Parameters:
 212  214   *   connection (input) - connection handle.
 213  215   *   body       (input) - request message body.
 214  216   *
 215  217   * Returns:
 216  218   *   void
 217  219   */
 218  220  /*ARGSUSED*/
  
    | 
      ↓ open down ↓ | 
    102 lines elided | 
    
      ↑ open up ↑ | 
  
 219  221  void
 220  222  ndmpd_scsi_reset_device_v2(ndmp_connection_t *connection, void *body)
 221  223  {
 222  224          ndmp_scsi_reset_device_reply reply;
 223  225  
 224  226  
 225  227          ndmpd_session_t *session = ndmp_get_client_data(connection);
 226  228          struct uscsi_cmd  cmd;
 227  229  
 228  230          if (session->ns_scsi.sd_devid == -1) {
 229      -                NDMP_LOG(LOG_ERR, "SCSI device is not open.");
      231 +                syslog(LOG_ERR, "SCSI device is not open.");
 230  232                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 231  233          } else {
 232  234                  reply.error = NDMP_NO_ERR;
 233  235                  (void) memset((void*)&cmd, 0, sizeof (cmd));
 234  236                  cmd.uscsi_flags |= USCSI_RESET;
 235  237                  if (ioctl(session->ns_scsi.sd_devid, USCSICMD, &cmd) < 0) {
 236      -                        NDMP_LOG(LOG_ERR, "USCSI reset failed: %m.");
 237      -                        NDMP_LOG(LOG_DEBUG,
 238      -                            "ioctl(USCSICMD) USCSI_RESET failed: %m.");
      238 +                        syslog(LOG_ERR, "USCSI reset failed: %m.");
 239  239                          reply.error = NDMP_IO_ERR;
 240  240                  }
 241  241          }
 242  242  
 243  243          ndmp_send_reply(connection, (void *) &reply,
 244  244              "sending scsi_reset_device reply");
 245  245  }
 246  246  
 247  247  
 248  248  /*
 249  249   * ndmpd_scsi_reset_bus_v2
 250  250   *
 251  251   * This handler resets the currently targeted SCSI bus.
 252  252   *
 253  253   * Request not yet supported.
 254  254   *
 255  255   * Parameters:
 256  256   *   connection (input) - connection handle.
 257  257   *   body       (input) - request message body.
  
    | 
      ↓ open down ↓ | 
    9 lines elided | 
    
      ↑ open up ↑ | 
  
 258  258   *
 259  259   * Returns:
 260  260   *   void
 261  261   */
 262  262  /*ARGSUSED*/
 263  263  void
 264  264  ndmpd_scsi_reset_bus_v2(ndmp_connection_t *connection, void *body)
 265  265  {
 266  266          ndmp_scsi_reset_bus_reply reply;
 267  267  
 268      -        NDMP_LOG(LOG_DEBUG, "request not supported");
 269  268          reply.error = NDMP_NOT_SUPPORTED_ERR;
 270  269  
 271  270          ndmp_send_reply(connection, (void *) &reply,
 272  271              "sending scsi_reset_bus reply");
 273  272  }
 274  273  
 275  274  
 276  275  /*
 277  276   * ndmpd_scsi_execute_cdb_v2
 278  277   *
 279  278   * This handler sends the CDB to the currently targeted SCSI device.
 280  279   *
 281  280   * Parameters:
 282  281   *   connection (input) - connection handle.
 283  282   *   body       (input) - request message body.
 284  283   *
 285  284   * Returns:
 286  285   *   void
 287  286   */
 288  287  void
  
    | 
      ↓ open down ↓ | 
    10 lines elided | 
    
      ↑ open up ↑ | 
  
 289  288  ndmpd_scsi_execute_cdb_v2(ndmp_connection_t *connection, void *body)
 290  289  {
 291  290          ndmp_execute_cdb_request *request = (ndmp_execute_cdb_request *) body;
 292  291          ndmp_execute_cdb_reply reply;
 293  292          ndmpd_session_t *session = ndmp_get_client_data(connection);
 294  293  
 295  294          if (session->ns_scsi.sd_is_open == -1 ||
 296  295              !session->ns_scsi.sd_valid_target_set) {
 297  296                  (void) memset((void *) &reply, 0, sizeof (reply));
 298  297  
 299      -                NDMP_LOG(LOG_ERR, "SCSI device is not open.");
 300  298                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 301  299                  ndmp_send_reply(connection, (void *) &reply,
 302  300                      "sending scsi_execute_cdb reply");
 303  301          } else {
 304  302                  ndmp_execute_cdb(session, session->ns_scsi.sd_adapter_name,
 305  303                      session->ns_scsi.sd_sid, session->ns_scsi.sd_lun, request);
 306  304          }
 307  305  }
 308  306  
 309  307  
 310  308  /*
 311  309   * ************************************************************************
 312  310   * NDMP V3 HANDLERS
 313  311   * ************************************************************************
 314  312   */
 315  313  
 316  314  /*
 317  315   * ndmpd_scsi_open_v3
 318  316   *
 319  317   * This handler opens the specified SCSI device.
 320  318   *
 321  319   * Parameters:
 322  320   *   connection (input) - connection handle.
 323  321   *   body       (input) - request message body.
 324  322   *
 325  323   * Returns:
 326  324   *   void
 327  325   */
 328  326  void
 329  327  ndmpd_scsi_open_v3(ndmp_connection_t *connection, void *body)
 330  328  {
 331  329          ndmp_scsi_open_request_v3 *request = (ndmp_scsi_open_request_v3 *)body;
 332  330  
 333  331          common_open(connection, request->device);
 334  332  }
 335  333  
 336  334  
 337  335  /*
 338  336   * ndmpd_scsi_set_target_v3
 339  337   *
 340  338   * This handler sets the SCSI target of the SCSI device.
 341  339   * It is only valid to use this request if the opened SCSI device
 342  340   * is capable of talking to multiple SCSI targets.
 343  341   *
 344  342   * Parameters:
 345  343   *   connection (input) - connection handle.
 346  344   *   body       (input) - request message body.
 347  345   *
 348  346   * Returns:
 349  347   *   void
 350  348   */
 351  349  void
 352  350  ndmpd_scsi_set_target_v3(ndmp_connection_t *connection, void *body)
 353  351  {
 354  352          ndmp_scsi_set_target_request_v3 *request;
 355  353  
 356  354          request = (ndmp_scsi_set_target_request_v3 *) body;
 357  355  
 358  356          common_set_target(connection, request->device,
 359  357              request->target_controller, request->target_id,
 360  358              request->target_lun);
 361  359  }
 362  360  
 363  361  
 364  362  /*
 365  363   * ************************************************************************
 366  364   * NDMP V4 HANDLERS
 367  365   * ************************************************************************
 368  366   */
 369  367  
 370  368  /*
 371  369   * ************************************************************************
 372  370   * LOCALS
 373  371   * ************************************************************************
 374  372   */
 375  373  
 376  374  
 377  375  /*
 378  376   * scsi_open_send_reply
 379  377   *
 380  378   * Send a reply for SCSI open command
 381  379   *
 382  380   * Parameters:
 383  381   *   connection (input) - connection handle.
 384  382   *   err        (input) - ndmp error code
 385  383   *
 386  384   * Returns:
 387  385   *   void
 388  386   */
 389  387  static void
 390  388  scsi_open_send_reply(ndmp_connection_t *connection, int err)
 391  389  {
 392  390          ndmp_scsi_open_reply reply;
 393  391  
 394  392          reply.error = err;
 395  393          ndmp_send_reply(connection, (void *) &reply, "sending scsi_open reply");
 396  394  }
 397  395  
 398  396  
 399  397  /*
 400  398   * common_open
 401  399   *
 402  400   * Common SCSI open function for all NDMP versions
 403  401   *
 404  402   * Parameters:
 405  403   *   connection (input) - connection handle.
 406  404   *   devname (input) - device name to open.
 407  405   *
 408  406   * Returns:
  
    | 
      ↓ open down ↓ | 
    99 lines elided | 
    
      ↑ open up ↑ | 
  
 409  407   *   void
 410  408   */
 411  409  static void
 412  410  common_open(ndmp_connection_t *connection, char *devname)
 413  411  {
 414  412          ndmpd_session_t *session = ndmp_get_client_data(connection);
 415  413          char adptnm[SCSI_MAX_NAME];
 416  414          int sid, lun;
 417  415          int err;
 418  416          scsi_adapter_t *sa;
 419      -        int devid;
      417 +        int devid = -1;
 420  418  
 421  419          err = NDMP_NO_ERR;
 422  420  
 423  421          if (session->ns_tape.td_fd != -1 || session->ns_scsi.sd_is_open != -1) {
 424      -                NDMP_LOG(LOG_ERR,
 425      -                    "Session already has a tape or scsi device open.");
 426  422                  err = NDMP_DEVICE_OPENED_ERR;
 427  423          } else if ((sa = scsi_get_adapter(0)) != NULL) {
 428      -                NDMP_LOG(LOG_DEBUG, "Adapter device found: %s", devname);
 429  424                  (void) strlcpy(adptnm, devname, SCSI_MAX_NAME-2);
 430  425                  adptnm[SCSI_MAX_NAME-1] = '\0';
 431  426                  sid = lun = -1;
 432  427  
 433  428                  scsi_find_sid_lun(sa, devname, &sid, &lun);
 434  429                  if (ndmp_open_list_find(devname, sid, lun) == NULL &&
 435  430                      (devid = open(devname, O_RDWR | O_NDELAY)) < 0) {
 436      -                        NDMP_LOG(LOG_ERR, "Failed to open device %s: %m.",
      431 +                        syslog(LOG_ERR, "Failed to open device %s: %m.",
 437  432                              devname);
 438  433                          err = NDMP_NO_DEVICE_ERR;
 439  434                  }
 440  435          } else {
 441      -                NDMP_LOG(LOG_ERR, "%s: No such SCSI adapter.", devname);
      436 +                syslog(LOG_ERR, "%s: No such SCSI adapter.", devname);
 442  437                  err = NDMP_NO_DEVICE_ERR;
 443  438          }
 444  439  
 445  440          if (err != NDMP_NO_ERR) {
 446  441                  scsi_open_send_reply(connection, err);
 447  442                  return;
 448  443          }
 449  444  
 450  445          switch (ndmp_open_list_add(connection, adptnm, sid, lun, devid)) {
 451  446          case 0:
 452  447                  /* OK */
 453  448                  break;
 454  449          case EBUSY:
 455  450                  err = NDMP_DEVICE_BUSY_ERR;
 456  451                  break;
 457  452          case ENOMEM:
 458  453                  err = NDMP_NO_MEM_ERR;
 459  454                  break;
 460  455          default:
 461  456                  err = NDMP_IO_ERR;
 462  457          }
 463  458          if (err != NDMP_NO_ERR) {
 464  459                  scsi_open_send_reply(connection, err);
 465  460                  return;
 466  461          }
 467  462  
 468  463          (void) strlcpy(session->ns_scsi.sd_adapter_name, adptnm, SCSI_MAX_NAME);
 469  464          session->ns_scsi.sd_is_open = 1;
 470  465          session->ns_scsi.sd_devid = devid;
 471  466          if (sid != -1) {
 472  467                  session->ns_scsi.sd_sid = sid;
 473  468                  session->ns_scsi.sd_lun = lun;
 474  469                  session->ns_scsi.sd_valid_target_set = TRUE;
 475  470          } else {
 476  471                  session->ns_scsi.sd_sid = session->ns_scsi.sd_lun = -1;
 477  472                  session->ns_scsi.sd_valid_target_set = FALSE;
 478  473          }
 479  474  
 480  475          scsi_open_send_reply(connection, err);
 481  476  }
 482  477  
 483  478  
 484  479  /*
 485  480   * common_set_target
 486  481   *
 487  482   * Set the SCSI target (SCSI number, LUN number, controller number)
 488  483   *
 489  484   * Parameters:
 490  485   *   connection (input) - connection handle.
 491  486   *   device (input) - device name.
 492  487   *   controller (input) - controller number.
 493  488   *   sid (input) - SCSI target ID.
 494  489   *   lun (input) - LUN number.
 495  490   *
 496  491   * Returns:
 497  492   *   0: on success
 498  493   *  -1: otherwise
 499  494   */
 500  495  /*ARGSUSED*/
 501  496  static void
 502  497  common_set_target(ndmp_connection_t *connection, char *device,
 503  498      ushort_t controller, ushort_t sid, ushort_t lun)
 504  499  {
  
    | 
      ↓ open down ↓ | 
    53 lines elided | 
    
      ↑ open up ↑ | 
  
 505  500          ndmp_scsi_set_target_reply reply;
 506  501          ndmpd_session_t *session = ndmp_get_client_data(connection);
 507  502          int type;
 508  503  
 509  504          reply.error = NDMP_NO_ERR;
 510  505  
 511  506          if (session->ns_scsi.sd_is_open == -1) {
 512  507                  reply.error = NDMP_DEV_NOT_OPEN_ERR;
 513  508          } else if (!scsi_dev_exists(session->ns_scsi.sd_adapter_name, sid,
 514  509              lun)) {
 515      -                NDMP_LOG(LOG_ERR, "No such SCSI device: target %d lun %d.",
      510 +                syslog(LOG_ERR, "No such SCSI device: target %d lun %d.",
 516  511                      sid, lun);
 517  512                  reply.error = NDMP_NO_DEVICE_ERR;
 518  513          } else {
 519  514                  type = scsi_get_devtype(session->ns_scsi.sd_adapter_name, sid,
 520  515                      lun);
 521  516                  if (type != DTYPE_SEQUENTIAL && type != DTYPE_CHANGER) {
 522      -                        NDMP_LOG(LOG_ERR,
      517 +                        syslog(LOG_ERR,
 523  518                              "Not a tape or robot device: target %d lun %d.",
 524  519                              sid, lun);
 525  520                          reply.error = NDMP_ILLEGAL_ARGS_ERR;
 526  521                  }
 527  522          }
 528  523  
 529  524          if (reply.error != NDMP_NO_ERR) {
 530  525                  ndmp_send_reply(connection, (void *) &reply,
 531  526                      "sending scsi_set_target reply");
 532  527                  return;
 533  528          }
 534  529  
 535  530          /*
 536  531           * The open_list must be updated if the SID or LUN are going to be
 537  532           * changed.  Close uses the same SID & LUN for removing the entry
 538  533           * from the open_list.
 539  534           */
 540  535          if (sid != session->ns_scsi.sd_sid || lun != session->ns_scsi.sd_lun) {
 541  536                  switch (ndmp_open_list_add(connection,
 542  537                      session->ns_scsi.sd_adapter_name, sid, lun, 0)) {
 543  538                  case 0:
 544  539                          (void) ndmp_open_list_del(session->
 545  540                              ns_scsi.sd_adapter_name, session->ns_scsi.sd_sid,
 546  541                              session->ns_scsi.sd_lun);
 547  542                          break;
 548  543                  case EBUSY:
 549  544                          reply.error = NDMP_DEVICE_BUSY_ERR;
  
    | 
      ↓ open down ↓ | 
    17 lines elided | 
    
      ↑ open up ↑ | 
  
 550  545                          break;
 551  546                  case ENOMEM:
 552  547                          reply.error = NDMP_NO_MEM_ERR;
 553  548                          break;
 554  549                  default:
 555  550                          reply.error = NDMP_IO_ERR;
 556  551                  }
 557  552          }
 558  553  
 559  554          if (reply.error == NDMP_NO_ERR) {
 560      -                NDMP_LOG(LOG_DEBUG, "Updated sid %d lun %d", sid, lun);
 561  555                  session->ns_scsi.sd_sid = sid;
 562  556                  session->ns_scsi.sd_lun = lun;
 563  557                  session->ns_scsi.sd_valid_target_set = TRUE;
 564  558          }
 565  559  
 566  560          ndmp_send_reply(connection, (void *) &reply,
 567  561              "sending scsi_set_target reply");
 568  562  }
 569  563  
 570  564  /*
 571  565   * scsi_find_sid_lun
 572  566   *
 573  567   * gets the adapter, and returns the sid and lun number
 574  568   */
 575  569  void
 576  570  scsi_find_sid_lun(scsi_adapter_t *sa, char *devname, int *sid, int *lun)
 577  571  {
 578  572          scsi_link_t *sl;
 579  573          char *name;
 580  574  
 581  575          for (sl = sa->sa_link_head.sl_next; sl && sl != &sa->sa_link_head;
 582  576              sl = sl->sl_next) {
 583  577                  name = sasd_slink_name(sl);
 584  578                  if (strcmp(devname, name) == 0) {
 585  579                          *sid = sl->sl_sid;
 586  580                          *lun = sl->sl_lun;
 587  581                          return;
 588  582                  }
 589  583          }
 590  584  
 591  585          *sid = -1;
 592  586          *lun = -1;
 593  587  }
  
    | 
      ↓ open down ↓ | 
    23 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX