Print this page
    
NEX-2911 NDMP logging should use syslog and is too chatty
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/cmd/ndmpd/tlm/tlm_info.c
          +++ new/usr/src/cmd/ndmpd/tlm/tlm_info.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
  
    | 
      ↓ open down ↓ | 
    28 lines elided | 
    
      ↑ open up ↑ | 
  
  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
  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 +#include <syslog.h>
  39   40  #include <stdlib.h>
  40   41  #include "tlm.h"
  41   42  #include "tlm_proto.h"
  42   43  #include <sys/errno.h>
  43   44  
  44   45  
  45   46  extern  tlm_chain_link_t *tlm_un_ref(tlm_chain_link_t *old_top,
  46   47      tlm_chain_link_t *link);
  47   48  
  48   49  static  tlm_info_t tlm_info;
  49   50  
  50   51  /*
  51   52   * Mutex for concurrent access to job_stats
  52   53   */
  53   54  mutex_t jstat_mtx;
  54   55  
  55   56  
  56   57  /*
  57   58   * get the number of libraries
  58   59   */
  59   60  int
  60   61  tlm_library_count(void)
  61   62  {
  62   63          int     lib;
  63   64          tlm_library_t   *library;
  64   65  
  65   66          for (lib = 1; lib <= tlm_info.ti_library_count; lib++) {
  66   67                  library = tlm_library(lib);
  67   68                  if (library != NULL &&
  68   69                      library->tl_drive_count == 0) {
  69   70                          return (0);
  70   71                  }
  71   72          }
  72   73          return (tlm_info.ti_library_count);
  73   74  }
  74   75  
  75   76  /*
  76   77   * get the library whose number matches
  77   78   */
  78   79  tlm_library_t *
  79   80  tlm_library(int lib)
  80   81  {
  81   82          tlm_library_t   *library = tlm_info.ti_library;
  82   83          while (library != NULL) {
  83   84                  if (library->tl_number == lib) {
  84   85                          return (library);
  85   86                  }
  86   87                  library = library->tl_next;
  87   88          }
  88   89          errno = TLM_ERROR_RANGE;
  89   90          return (NULL);
  90   91  }
  91   92  
  92   93  /*
  93   94   * get the info about this drive
  94   95   */
  95   96  tlm_drive_t *
  96   97  tlm_drive(int lib, int drv)
  97   98  {
  98   99          tlm_drive_t     *drive;
  99  100          tlm_library_t   *library = tlm_library(lib);
 100  101  
 101  102          if (library == NULL) {
 102  103                  return (NULL);
 103  104          }
 104  105          drive = library->tl_drive;
 105  106          while (drive != NULL) {
 106  107                  if (drv == drive->td_number) {
 107  108                          return (drive);
 108  109                  }
 109  110                  drive = drive->td_next;
 110  111          }
 111  112          return (NULL);
 112  113  }
 113  114  
 114  115  /*
 115  116   * get the info about this slot
 116  117   */
 117  118  tlm_slot_t *
 118  119  tlm_slot(int lib, int slt)
 119  120  {
 120  121          tlm_slot_t      *slot = NULL;
 121  122          tlm_library_t   *library = tlm_library(lib);
 122  123  
 123  124          if (library != NULL)
 124  125                  slot = library->tl_slot;
 125  126          while (slot != NULL) {
 126  127                  if (slt == slot->ts_number) {
 127  128                          return (slot);
 128  129                  }
 129  130                  slot = slot->ts_next;
 130  131          }
 131  132          return (NULL);
 132  133  }
 133  134  
 134  135  /*
 135  136   * add a link to the INFO chain
 136  137   */
 137  138  tlm_job_stats_t *
 138  139  tlm_new_job_stats(char *name)
 139  140  {
 140  141          tlm_chain_link_t *new_link;
 141  142          tlm_job_stats_t *job_stats;
 142  143  
 143  144          new_link = ndmp_malloc(sizeof (tlm_chain_link_t));
 144  145          if (new_link == 0)
 145  146                  return (0);
 146  147  
 147  148          job_stats = ndmp_malloc(sizeof (tlm_job_stats_t));
 148  149          if (job_stats == 0) {
 149  150                  free(new_link);
 150  151                  return (0);
 151  152          }
 152  153  
 153  154          new_link->tc_ref_count = 1;
 154  155          new_link->tc_data = (void *)job_stats;
 155  156          (void) strlcpy(job_stats->js_job_name, name, TLM_MAX_BACKUP_JOB_NAME);
 156  157  
 157  158          (void) mutex_lock(&jstat_mtx);
 158  159          if (tlm_info.ti_job_stats == 0) {
 159  160                  new_link->tc_next = new_link;
 160  161                  new_link->tc_prev = new_link;
 161  162          } else {
 162  163                  tlm_chain_link_t *next_link = tlm_info.ti_job_stats;
 163  164                  tlm_chain_link_t *prev_link = next_link->tc_prev;
 164  165  
 165  166                  new_link->tc_next = next_link;
 166  167                  new_link->tc_prev = prev_link;
 167  168                  prev_link->tc_next = new_link;
 168  169                  next_link->tc_prev = new_link;
 169  170          }
 170  171          tlm_info.ti_job_stats = new_link;
 171  172          (void) mutex_unlock(&jstat_mtx);
 172  173  
 173  174          return (job_stats);
 174  175  }
 175  176  
 176  177  /*
 177  178   * make sure this Job Stats buffer is not deleted while we use it
 178  179   */
 179  180  tlm_job_stats_t *
 180  181  tlm_ref_job_stats(char *name)
 181  182  {
 182  183          static  tlm_job_stats_t fake_job_stats;
 183  184          tlm_chain_link_t        *link;
 184  185  
 185  186          (void) mutex_lock(&jstat_mtx);
 186  187          link = tlm_info.ti_job_stats;
 187  188          if (link == 0) {
 188  189                  /*
 189  190                   * our tables are empty
 190  191                   */
 191  192                  (void) mutex_unlock(&jstat_mtx);
 192  193                  return (&fake_job_stats);
 193  194          }
 194  195  
 195  196          do {
  
    | 
      ↓ open down ↓ | 
    147 lines elided | 
    
      ↑ open up ↑ | 
  
 196  197                  tlm_job_stats_t *job_stats;
 197  198                  job_stats = (tlm_job_stats_t *)link->tc_data;
 198  199  
 199  200                  if (strcmp(job_stats->js_job_name, name) == 0) {
 200  201                          link->tc_ref_count++;
 201  202                          (void) mutex_unlock(&jstat_mtx);
 202  203                          return (job_stats);
 203  204                  }
 204  205                  link = link->tc_next;
 205  206          } while (link != tlm_info.ti_job_stats);
 206      -        NDMP_LOG(LOG_DEBUG,
      207 +        syslog(LOG_DEBUG,
 207  208              "TAPE BACKUP> Ref for job [%s] was not found", name);
 208  209          (void) mutex_unlock(&jstat_mtx);
 209  210  
 210  211          return (&fake_job_stats);
 211  212  }
 212  213  
 213  214  /*
 214  215   * remove a link to the INFO chain
 215  216   */
 216  217  void
 217  218  tlm_un_ref_job_stats(char *name)
 218  219  {
 219  220          tlm_chain_link_t *link;
 220  221  
 221  222          (void) mutex_lock(&jstat_mtx);
 222  223          link = tlm_info.ti_job_stats;
 223  224          if (link == 0) {
 224      -                NDMP_LOG(LOG_DEBUG, "TAPE BACKUP>"
      225 +                syslog(LOG_DEBUG, "TAPE BACKUP>"
 225  226                      " Internal error for job [%s], could not delete", name);
 226  227                  return;
 227  228          }
 228  229          do {
 229  230                  tlm_job_stats_t *job_stats;
 230  231                  job_stats = (tlm_job_stats_t *)link->tc_data;
 231  232  
 232  233                  if (strcmp(job_stats->js_job_name, name) == 0) {
 233  234                          tlm_info.ti_job_stats =
 234  235                              tlm_un_ref(tlm_info.ti_job_stats, link);
 235  236                          (void) mutex_unlock(&jstat_mtx);
 236  237                          return;
 237  238                  }
 238  239                  link = link->tc_next;
 239  240          } while (link != tlm_info.ti_job_stats);
 240  241          (void) mutex_unlock(&jstat_mtx);
 241      -        NDMP_LOG(LOG_DEBUG,
      242 +        syslog(LOG_DEBUG,
 242  243              "TAPE BACKUP> Delete for job [%s] was not found", name);
 243  244  }
 244  245  
 245  246  /*
 246  247   * one party does not care about this blob, can we let it go?
 247  248   */
 248  249  tlm_chain_link_t *
 249  250  tlm_un_ref(tlm_chain_link_t *old_top, tlm_chain_link_t *link)
 250  251  {
 251  252          tlm_chain_link_t *chain_link = old_top;
 252  253          tlm_chain_link_t *new_top;
 253  254  
 254  255          /*
 255  256           * count down the number of
 256  257           * interested parties for this blob
 257  258           */
 258  259          link->tc_ref_count--;
 259  260          if (link->tc_ref_count > 0) {
 260  261                  /*
 261  262                   * there is still interest in this blob,
 262  263                   * no change yet
 263  264                   *
 264  265                   * returning "old_top" means there is no change in the links
 265  266                   */
 266  267                  return (old_top);
 267  268          }
 268  269  
 269  270          /*
 270  271           * no one cares about this data anymore
 271  272           * find out how to delete it
 272  273           */
 273  274          do {
 274  275                  if (chain_link == link) {
 275  276                          tlm_chain_link_t *next;
 276  277                          tlm_chain_link_t *prev;
 277  278  
 278  279                          /*
 279  280                           * If there are one or two elements in the list, then
 280  281                           * the prev and next pointers point to one element in
 281  282                           * the list, the element itself and the other element
 282  283                           * correspondingly.  So we must distinguish if there
 283  284                           * are only one or two elements in the list.  If
 284  285                           * either of the 'prev' or 'next' pointers point to
 285  286                           * the link itself, then we have only one element in
 286  287                           * the list.
 287  288                           */
 288  289                          if (link->tc_next == link->tc_prev &&
 289  290                              link->tc_next == link) {
 290  291                                  /*
 291  292                                   * there is only this one link in the chain
 292  293                                   * delete this and the chain is empty
 293  294                                   */
 294  295                                  new_top = 0;
 295  296                          } else {
 296  297                                  new_top = link->tc_next;
 297  298                          }
  
    | 
      ↓ open down ↓ | 
    46 lines elided | 
    
      ↑ open up ↑ | 
  
 298  299                          next = link->tc_next;
 299  300                          prev = link->tc_prev;
 300  301                          prev->tc_next = next;
 301  302                          next->tc_prev = prev;
 302  303                          free(link->tc_data);
 303  304                          free(link);
 304  305                          return (new_top);
 305  306                  }
 306  307                  chain_link = chain_link->tc_next;
 307  308          } while (chain_link != old_top);
 308      -        NDMP_LOG(LOG_DEBUG, "TAPE BACKUP> un_ref target not found.");
      309 +        syslog(LOG_DEBUG, "TAPE BACKUP> un_ref target not found.");
 309  310          return (old_top);
 310  311  }
 311  312  
 312  313  /*
 313  314   * the following section is global, but not really part of the
 314  315   * public interface.  Use of this outside of the tlm_*.c files
 315  316   * is for special cases only.
 316  317   */
 317  318  
 318  319  /*
 319  320   * add a new tape library data blob to the list of libraries
 320  321   * returns the new tape library data blob just created
 321  322   */
 322  323  int
 323  324  tlm_insert_new_library(scsi_link_t *slink)
 324  325  {
 325  326          tlm_library_t **p_library = &tlm_info.ti_library;
 326  327          tlm_library_t *library = ndmp_malloc(sizeof (tlm_library_t));
 327  328  
 328  329          while (*p_library != NULL) {
 329  330                  p_library = &(*p_library)->tl_next;
 330  331          }
 331  332          tlm_info.ti_library_count++;
 332  333          library->tl_number = tlm_info.ti_library_count;
 333  334          library->tl_slink = slink;
 334  335          library->tl_capability_robot = TRUE;
 335  336          *p_library = library;
 336  337          return (library->tl_number);
 337  338  }
 338  339  
 339  340  /*
 340  341   * add a new tape drive data blob to the list of drives in a library
 341  342   * returns the new tape drive data blob just created
 342  343   */
 343  344  int
 344  345  tlm_insert_new_drive(int lib)
 345  346  {
 346  347          tlm_library_t *library = tlm_library(lib);
 347  348          tlm_drive_t *drive = ndmp_malloc(sizeof (tlm_drive_t));
 348  349          tlm_drive_t **p_drive = &library->tl_drive;
 349  350  
 350  351          while (*p_drive != NULL) {
 351  352                  p_drive = &(*p_drive)->td_next;
 352  353          }
 353  354          library->tl_drive_count++;
 354  355          library->tl_capability_drives = TRUE;
 355  356  
 356  357          drive->td_library = library;
 357  358          drive->td_number = library->tl_drive_count;
 358  359          *p_drive = drive;
 359  360          return (drive->td_number);
 360  361  }
 361  362  
 362  363  /*
 363  364   * add a new tape slot data blob to the list of slots in a library
 364  365   * returns the new tape slot data blob just created
 365  366   */
 366  367  int
 367  368  tlm_insert_new_slot(int lib)
 368  369  {
 369  370          tlm_library_t *library = tlm_library(lib);
 370  371          tlm_slot_t *slot = ndmp_malloc(sizeof (tlm_slot_t));
 371  372          tlm_slot_t **p_slot = &library->tl_slot;
 372  373  
 373  374          while (*p_slot != NULL) {
 374  375                  p_slot = &(*p_slot)->ts_next;
 375  376          }
 376  377          library->tl_slot_count++;
 377  378          library->tl_capability_slots = TRUE;
 378  379  
 379  380          slot->ts_library = library;
 380  381          slot->ts_number = library->tl_slot_count;
 381  382          *p_slot = slot;
 382  383          return (slot->ts_number);
 383  384  }
  
    | 
      ↓ open down ↓ | 
    65 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX