iscsi_target_device.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*******************************************************************************
  2. * This file contains the iSCSI Virtual Device and Disk Transport
  3. * agnostic related functions.
  4. *
  5. * (c) Copyright 2007-2013 Datera, Inc.
  6. *
  7. * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. ******************************************************************************/
  19. #include <scsi/scsi_device.h>
  20. #include <target/target_core_base.h>
  21. #include <target/target_core_fabric.h>
  22. #include "iscsi_target_core.h"
  23. #include "iscsi_target_device.h"
  24. #include "iscsi_target_tpg.h"
  25. #include "iscsi_target_util.h"
  26. void iscsit_determine_maxcmdsn(struct iscsi_session *sess)
  27. {
  28. struct se_node_acl *se_nacl;
  29. /*
  30. * This is a discovery session, the single queue slot was already
  31. * assigned in iscsi_login_zero_tsih(). Since only Logout and
  32. * Text Opcodes are allowed during discovery we do not have to worry
  33. * about the HBA's queue depth here.
  34. */
  35. if (sess->sess_ops->SessionType)
  36. return;
  37. se_nacl = sess->se_sess->se_node_acl;
  38. /*
  39. * This is a normal session, set the Session's CmdSN window to the
  40. * struct se_node_acl->queue_depth. The value in struct se_node_acl->queue_depth
  41. * has already been validated as a legal value in
  42. * core_set_queue_depth_for_node().
  43. */
  44. sess->cmdsn_window = se_nacl->queue_depth;
  45. sess->max_cmd_sn = (sess->max_cmd_sn + se_nacl->queue_depth) - 1;
  46. }
  47. void iscsit_increment_maxcmdsn(struct iscsi_cmd *cmd, struct iscsi_session *sess)
  48. {
  49. if (cmd->immediate_cmd || cmd->maxcmdsn_inc)
  50. return;
  51. cmd->maxcmdsn_inc = 1;
  52. if (!mutex_trylock(&sess->cmdsn_mutex)) {
  53. sess->max_cmd_sn += 1;
  54. pr_debug("Updated MaxCmdSN to 0x%08x\n", sess->max_cmd_sn);
  55. return;
  56. }
  57. sess->max_cmd_sn += 1;
  58. pr_debug("Updated MaxCmdSN to 0x%08x\n", sess->max_cmd_sn);
  59. mutex_unlock(&sess->cmdsn_mutex);
  60. }
  61. EXPORT_SYMBOL(iscsit_increment_maxcmdsn);