diff options
Diffstat (limited to 'drivers/scsi/scsi_transport_iscsi.c')
-rw-r--r-- | drivers/scsi/scsi_transport_iscsi.c | 262 |
1 files changed, 131 insertions, 131 deletions
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index 59a1c9d9d3bd..71e54a64adca 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c | |||
@@ -39,10 +39,6 @@ struct iscsi_internal { | |||
39 | struct iscsi_transport *iscsi_transport; | 39 | struct iscsi_transport *iscsi_transport; |
40 | struct list_head list; | 40 | struct list_head list; |
41 | /* | 41 | /* |
42 | * List of sessions for this transport | ||
43 | */ | ||
44 | struct list_head sessions; | ||
45 | /* | ||
46 | * based on transport capabilities, at register time we set these | 42 | * based on transport capabilities, at register time we set these |
47 | * bits to tell the transport class it wants attributes displayed | 43 | * bits to tell the transport class it wants attributes displayed |
48 | * in sysfs or that it can support different iSCSI Data-Path | 44 | * in sysfs or that it can support different iSCSI Data-Path |
@@ -164,9 +160,43 @@ static struct mempool_zone *z_reply; | |||
164 | #define Z_MAX_ERROR 16 | 160 | #define Z_MAX_ERROR 16 |
165 | #define Z_HIWAT_ERROR 12 | 161 | #define Z_HIWAT_ERROR 12 |
166 | 162 | ||
163 | static LIST_HEAD(sesslist); | ||
164 | static DEFINE_SPINLOCK(sesslock); | ||
167 | static LIST_HEAD(connlist); | 165 | static LIST_HEAD(connlist); |
168 | static DEFINE_SPINLOCK(connlock); | 166 | static DEFINE_SPINLOCK(connlock); |
169 | 167 | ||
168 | static struct iscsi_cls_session *iscsi_session_lookup(uint64_t handle) | ||
169 | { | ||
170 | unsigned long flags; | ||
171 | struct iscsi_cls_session *sess; | ||
172 | |||
173 | spin_lock_irqsave(&sesslock, flags); | ||
174 | list_for_each_entry(sess, &sesslist, sess_list) { | ||
175 | if (sess == iscsi_ptr(handle)) { | ||
176 | spin_unlock_irqrestore(&sesslock, flags); | ||
177 | return sess; | ||
178 | } | ||
179 | } | ||
180 | spin_unlock_irqrestore(&sesslock, flags); | ||
181 | return NULL; | ||
182 | } | ||
183 | |||
184 | static struct iscsi_cls_conn *iscsi_conn_lookup(uint64_t handle) | ||
185 | { | ||
186 | unsigned long flags; | ||
187 | struct iscsi_cls_conn *conn; | ||
188 | |||
189 | spin_lock_irqsave(&connlock, flags); | ||
190 | list_for_each_entry(conn, &connlist, conn_list) { | ||
191 | if (conn == iscsi_ptr(handle)) { | ||
192 | spin_unlock_irqrestore(&connlock, flags); | ||
193 | return conn; | ||
194 | } | ||
195 | } | ||
196 | spin_unlock_irqrestore(&connlock, flags); | ||
197 | return NULL; | ||
198 | } | ||
199 | |||
170 | /* | 200 | /* |
171 | * The following functions can be used by LLDs that allocate | 201 | * The following functions can be used by LLDs that allocate |
172 | * their own scsi_hosts or by software iscsi LLDs | 202 | * their own scsi_hosts or by software iscsi LLDs |
@@ -365,6 +395,7 @@ iscsi_transport_create_session(struct scsi_transport_template *scsit, | |||
365 | { | 395 | { |
366 | struct iscsi_cls_session *session; | 396 | struct iscsi_cls_session *session; |
367 | struct Scsi_Host *shost; | 397 | struct Scsi_Host *shost; |
398 | unsigned long flags; | ||
368 | 399 | ||
369 | shost = scsi_host_alloc(transport->host_template, | 400 | shost = scsi_host_alloc(transport->host_template, |
370 | hostdata_privsize(transport)); | 401 | hostdata_privsize(transport)); |
@@ -389,6 +420,9 @@ iscsi_transport_create_session(struct scsi_transport_template *scsit, | |||
389 | goto remove_host; | 420 | goto remove_host; |
390 | 421 | ||
391 | *(unsigned long*)shost->hostdata = (unsigned long)session; | 422 | *(unsigned long*)shost->hostdata = (unsigned long)session; |
423 | spin_lock_irqsave(&sesslock, flags); | ||
424 | list_add(&session->sess_list, &sesslist); | ||
425 | spin_unlock_irqrestore(&sesslock, flags); | ||
392 | return shost; | 426 | return shost; |
393 | 427 | ||
394 | remove_host: | 428 | remove_host: |
@@ -410,9 +444,13 @@ EXPORT_SYMBOL_GPL(iscsi_transport_create_session); | |||
410 | int iscsi_transport_destroy_session(struct Scsi_Host *shost) | 444 | int iscsi_transport_destroy_session(struct Scsi_Host *shost) |
411 | { | 445 | { |
412 | struct iscsi_cls_session *session; | 446 | struct iscsi_cls_session *session; |
447 | unsigned long flags; | ||
413 | 448 | ||
414 | scsi_remove_host(shost); | 449 | scsi_remove_host(shost); |
415 | session = hostdata_session(shost->hostdata); | 450 | session = hostdata_session(shost->hostdata); |
451 | spin_lock_irqsave(&sesslock, flags); | ||
452 | list_del(&session->sess_list); | ||
453 | spin_unlock_irqrestore(&sesslock, flags); | ||
416 | iscsi_destroy_session(session); | 454 | iscsi_destroy_session(session); |
417 | /* ref from host alloc */ | 455 | /* ref from host alloc */ |
418 | scsi_host_put(shost); | 456 | scsi_host_put(shost); |
@@ -424,22 +462,6 @@ EXPORT_SYMBOL_GPL(iscsi_transport_destroy_session); | |||
424 | /* | 462 | /* |
425 | * iscsi interface functions | 463 | * iscsi interface functions |
426 | */ | 464 | */ |
427 | static struct iscsi_cls_conn* | ||
428 | iscsi_if_find_conn(uint64_t key) | ||
429 | { | ||
430 | unsigned long flags; | ||
431 | struct iscsi_cls_conn *conn; | ||
432 | |||
433 | spin_lock_irqsave(&connlock, flags); | ||
434 | list_for_each_entry(conn, &connlist, conn_list) | ||
435 | if (conn->connh == key) { | ||
436 | spin_unlock_irqrestore(&connlock, flags); | ||
437 | return conn; | ||
438 | } | ||
439 | spin_unlock_irqrestore(&connlock, flags); | ||
440 | return NULL; | ||
441 | } | ||
442 | |||
443 | static struct iscsi_internal * | 465 | static struct iscsi_internal * |
444 | iscsi_if_transport_lookup(struct iscsi_transport *tt) | 466 | iscsi_if_transport_lookup(struct iscsi_transport *tt) |
445 | { | 467 | { |
@@ -463,7 +485,7 @@ static inline struct list_head *skb_to_lh(struct sk_buff *skb) | |||
463 | } | 485 | } |
464 | 486 | ||
465 | static void* | 487 | static void* |
466 | mempool_zone_alloc_skb(unsigned int gfp_mask, void *pool_data) | 488 | mempool_zone_alloc_skb(gfp_t gfp_mask, void *pool_data) |
467 | { | 489 | { |
468 | struct mempool_zone *zone = pool_data; | 490 | struct mempool_zone *zone = pool_data; |
469 | 491 | ||
@@ -504,6 +526,12 @@ mempool_zone_init(unsigned max, unsigned size, unsigned hiwat) | |||
504 | if (!zp) | 526 | if (!zp) |
505 | return NULL; | 527 | return NULL; |
506 | 528 | ||
529 | zp->size = size; | ||
530 | zp->hiwat = hiwat; | ||
531 | INIT_LIST_HEAD(&zp->freequeue); | ||
532 | spin_lock_init(&zp->freelock); | ||
533 | atomic_set(&zp->allocated, 0); | ||
534 | |||
507 | zp->pool = mempool_create(max, mempool_zone_alloc_skb, | 535 | zp->pool = mempool_create(max, mempool_zone_alloc_skb, |
508 | mempool_zone_free_skb, zp); | 536 | mempool_zone_free_skb, zp); |
509 | if (!zp->pool) { | 537 | if (!zp->pool) { |
@@ -511,13 +539,6 @@ mempool_zone_init(unsigned max, unsigned size, unsigned hiwat) | |||
511 | return NULL; | 539 | return NULL; |
512 | } | 540 | } |
513 | 541 | ||
514 | zp->size = size; | ||
515 | zp->hiwat = hiwat; | ||
516 | |||
517 | INIT_LIST_HEAD(&zp->freequeue); | ||
518 | spin_lock_init(&zp->freelock); | ||
519 | atomic_set(&zp->allocated, 0); | ||
520 | |||
521 | return zp; | 542 | return zp; |
522 | } | 543 | } |
523 | 544 | ||
@@ -559,25 +580,21 @@ iscsi_unicast_skb(struct mempool_zone *zone, struct sk_buff *skb) | |||
559 | return 0; | 580 | return 0; |
560 | } | 581 | } |
561 | 582 | ||
562 | int iscsi_recv_pdu(iscsi_connh_t connh, struct iscsi_hdr *hdr, | 583 | int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr, |
563 | char *data, uint32_t data_size) | 584 | char *data, uint32_t data_size) |
564 | { | 585 | { |
565 | struct nlmsghdr *nlh; | 586 | struct nlmsghdr *nlh; |
566 | struct sk_buff *skb; | 587 | struct sk_buff *skb; |
567 | struct iscsi_uevent *ev; | 588 | struct iscsi_uevent *ev; |
568 | struct iscsi_cls_conn *conn; | ||
569 | char *pdu; | 589 | char *pdu; |
570 | int len = NLMSG_SPACE(sizeof(*ev) + sizeof(struct iscsi_hdr) + | 590 | int len = NLMSG_SPACE(sizeof(*ev) + sizeof(struct iscsi_hdr) + |
571 | data_size); | 591 | data_size); |
572 | 592 | ||
573 | conn = iscsi_if_find_conn(connh); | ||
574 | BUG_ON(!conn); | ||
575 | |||
576 | mempool_zone_complete(conn->z_pdu); | 593 | mempool_zone_complete(conn->z_pdu); |
577 | 594 | ||
578 | skb = mempool_zone_get_skb(conn->z_pdu); | 595 | skb = mempool_zone_get_skb(conn->z_pdu); |
579 | if (!skb) { | 596 | if (!skb) { |
580 | iscsi_conn_error(connh, ISCSI_ERR_CONN_FAILED); | 597 | iscsi_conn_error(conn, ISCSI_ERR_CONN_FAILED); |
581 | dev_printk(KERN_ERR, &conn->dev, "iscsi: can not deliver " | 598 | dev_printk(KERN_ERR, &conn->dev, "iscsi: can not deliver " |
582 | "control PDU: OOM\n"); | 599 | "control PDU: OOM\n"); |
583 | return -ENOMEM; | 600 | return -ENOMEM; |
@@ -590,7 +607,7 @@ int iscsi_recv_pdu(iscsi_connh_t connh, struct iscsi_hdr *hdr, | |||
590 | ev->type = ISCSI_KEVENT_RECV_PDU; | 607 | ev->type = ISCSI_KEVENT_RECV_PDU; |
591 | if (atomic_read(&conn->z_pdu->allocated) >= conn->z_pdu->hiwat) | 608 | if (atomic_read(&conn->z_pdu->allocated) >= conn->z_pdu->hiwat) |
592 | ev->iferror = -ENOMEM; | 609 | ev->iferror = -ENOMEM; |
593 | ev->r.recv_req.conn_handle = connh; | 610 | ev->r.recv_req.conn_handle = iscsi_handle(conn); |
594 | pdu = (char*)ev + sizeof(*ev); | 611 | pdu = (char*)ev + sizeof(*ev); |
595 | memcpy(pdu, hdr, sizeof(struct iscsi_hdr)); | 612 | memcpy(pdu, hdr, sizeof(struct iscsi_hdr)); |
596 | memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size); | 613 | memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size); |
@@ -599,17 +616,13 @@ int iscsi_recv_pdu(iscsi_connh_t connh, struct iscsi_hdr *hdr, | |||
599 | } | 616 | } |
600 | EXPORT_SYMBOL_GPL(iscsi_recv_pdu); | 617 | EXPORT_SYMBOL_GPL(iscsi_recv_pdu); |
601 | 618 | ||
602 | void iscsi_conn_error(iscsi_connh_t connh, enum iscsi_err error) | 619 | void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error) |
603 | { | 620 | { |
604 | struct nlmsghdr *nlh; | 621 | struct nlmsghdr *nlh; |
605 | struct sk_buff *skb; | 622 | struct sk_buff *skb; |
606 | struct iscsi_uevent *ev; | 623 | struct iscsi_uevent *ev; |
607 | struct iscsi_cls_conn *conn; | ||
608 | int len = NLMSG_SPACE(sizeof(*ev)); | 624 | int len = NLMSG_SPACE(sizeof(*ev)); |
609 | 625 | ||
610 | conn = iscsi_if_find_conn(connh); | ||
611 | BUG_ON(!conn); | ||
612 | |||
613 | mempool_zone_complete(conn->z_error); | 626 | mempool_zone_complete(conn->z_error); |
614 | 627 | ||
615 | skb = mempool_zone_get_skb(conn->z_error); | 628 | skb = mempool_zone_get_skb(conn->z_error); |
@@ -626,7 +639,7 @@ void iscsi_conn_error(iscsi_connh_t connh, enum iscsi_err error) | |||
626 | if (atomic_read(&conn->z_error->allocated) >= conn->z_error->hiwat) | 639 | if (atomic_read(&conn->z_error->allocated) >= conn->z_error->hiwat) |
627 | ev->iferror = -ENOMEM; | 640 | ev->iferror = -ENOMEM; |
628 | ev->r.connerror.error = error; | 641 | ev->r.connerror.error = error; |
629 | ev->r.connerror.conn_handle = connh; | 642 | ev->r.connerror.conn_handle = iscsi_handle(conn); |
630 | 643 | ||
631 | iscsi_unicast_skb(conn->z_error, skb); | 644 | iscsi_unicast_skb(conn->z_error, skb); |
632 | 645 | ||
@@ -662,8 +675,7 @@ iscsi_if_send_reply(int pid, int seq, int type, int done, int multi, | |||
662 | } | 675 | } |
663 | 676 | ||
664 | static int | 677 | static int |
665 | iscsi_if_get_stats(struct iscsi_transport *transport, struct sk_buff *skb, | 678 | iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh) |
666 | struct nlmsghdr *nlh) | ||
667 | { | 679 | { |
668 | struct iscsi_uevent *ev = NLMSG_DATA(nlh); | 680 | struct iscsi_uevent *ev = NLMSG_DATA(nlh); |
669 | struct iscsi_stats *stats; | 681 | struct iscsi_stats *stats; |
@@ -677,7 +689,7 @@ iscsi_if_get_stats(struct iscsi_transport *transport, struct sk_buff *skb, | |||
677 | ISCSI_STATS_CUSTOM_MAX); | 689 | ISCSI_STATS_CUSTOM_MAX); |
678 | int err = 0; | 690 | int err = 0; |
679 | 691 | ||
680 | conn = iscsi_if_find_conn(ev->u.get_stats.conn_handle); | 692 | conn = iscsi_conn_lookup(ev->u.get_stats.conn_handle); |
681 | if (!conn) | 693 | if (!conn) |
682 | return -EEXIST; | 694 | return -EEXIST; |
683 | 695 | ||
@@ -707,14 +719,14 @@ iscsi_if_get_stats(struct iscsi_transport *transport, struct sk_buff *skb, | |||
707 | ((char*)evstat + sizeof(*evstat)); | 719 | ((char*)evstat + sizeof(*evstat)); |
708 | memset(stats, 0, sizeof(*stats)); | 720 | memset(stats, 0, sizeof(*stats)); |
709 | 721 | ||
710 | transport->get_stats(ev->u.get_stats.conn_handle, stats); | 722 | transport->get_stats(conn, stats); |
711 | actual_size = NLMSG_SPACE(sizeof(struct iscsi_uevent) + | 723 | actual_size = NLMSG_SPACE(sizeof(struct iscsi_uevent) + |
712 | sizeof(struct iscsi_stats) + | 724 | sizeof(struct iscsi_stats) + |
713 | sizeof(struct iscsi_stats_custom) * | 725 | sizeof(struct iscsi_stats_custom) * |
714 | stats->custom_length); | 726 | stats->custom_length); |
715 | actual_size -= sizeof(*nlhstat); | 727 | actual_size -= sizeof(*nlhstat); |
716 | actual_size = NLMSG_LENGTH(actual_size); | 728 | actual_size = NLMSG_LENGTH(actual_size); |
717 | skb_trim(skb, NLMSG_ALIGN(actual_size)); | 729 | skb_trim(skbstat, NLMSG_ALIGN(actual_size)); |
718 | nlhstat->nlmsg_len = actual_size; | 730 | nlhstat->nlmsg_len = actual_size; |
719 | 731 | ||
720 | err = iscsi_unicast_skb(conn->z_pdu, skbstat); | 732 | err = iscsi_unicast_skb(conn->z_pdu, skbstat); |
@@ -727,58 +739,34 @@ static int | |||
727 | iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_uevent *ev) | 739 | iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_uevent *ev) |
728 | { | 740 | { |
729 | struct iscsi_transport *transport = priv->iscsi_transport; | 741 | struct iscsi_transport *transport = priv->iscsi_transport; |
730 | struct Scsi_Host *shost; | 742 | struct iscsi_cls_session *session; |
731 | 743 | uint32_t sid; | |
732 | if (!transport->create_session) | ||
733 | return -EINVAL; | ||
734 | 744 | ||
735 | shost = transport->create_session(&priv->t, | 745 | session = transport->create_session(&priv->t, |
736 | ev->u.c_session.initial_cmdsn); | 746 | ev->u.c_session.initial_cmdsn, |
737 | if (!shost) | 747 | &sid); |
748 | if (!session) | ||
738 | return -ENOMEM; | 749 | return -ENOMEM; |
739 | 750 | ||
740 | ev->r.c_session_ret.session_handle = iscsi_handle(iscsi_hostdata(shost->hostdata)); | 751 | ev->r.c_session_ret.session_handle = iscsi_handle(session); |
741 | ev->r.c_session_ret.sid = shost->host_no; | 752 | ev->r.c_session_ret.sid = sid; |
742 | return 0; | 753 | return 0; |
743 | } | 754 | } |
744 | 755 | ||
745 | static int | 756 | static int |
746 | iscsi_if_destroy_session(struct iscsi_internal *priv, struct iscsi_uevent *ev) | 757 | iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
747 | { | 758 | { |
748 | struct iscsi_transport *transport = priv->iscsi_transport; | ||
749 | |||
750 | struct Scsi_Host *shost; | ||
751 | |||
752 | if (!transport->destroy_session) | ||
753 | return -EINVAL; | ||
754 | |||
755 | shost = scsi_host_lookup(ev->u.d_session.sid); | ||
756 | if (shost == ERR_PTR(-ENXIO)) | ||
757 | return -EEXIST; | ||
758 | |||
759 | if (transport->destroy_session) | ||
760 | transport->destroy_session(shost); | ||
761 | /* ref from host lookup */ | ||
762 | scsi_host_put(shost); | ||
763 | return 0; | ||
764 | } | ||
765 | |||
766 | static int | ||
767 | iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev){ | ||
768 | struct Scsi_Host *shost; | ||
769 | struct iscsi_cls_conn *conn; | 759 | struct iscsi_cls_conn *conn; |
760 | struct iscsi_cls_session *session; | ||
770 | unsigned long flags; | 761 | unsigned long flags; |
771 | 762 | ||
772 | if (!transport->create_conn) | 763 | session = iscsi_session_lookup(ev->u.c_conn.session_handle); |
764 | if (!session) | ||
773 | return -EINVAL; | 765 | return -EINVAL; |
774 | 766 | ||
775 | shost = scsi_host_lookup(ev->u.c_conn.sid); | 767 | conn = transport->create_conn(session, ev->u.c_conn.cid); |
776 | if (shost == ERR_PTR(-ENXIO)) | ||
777 | return -EEXIST; | ||
778 | |||
779 | conn = transport->create_conn(shost, ev->u.c_conn.cid); | ||
780 | if (!conn) | 768 | if (!conn) |
781 | goto release_ref; | 769 | return -ENOMEM; |
782 | 770 | ||
783 | conn->z_pdu = mempool_zone_init(Z_MAX_PDU, | 771 | conn->z_pdu = mempool_zone_init(Z_MAX_PDU, |
784 | NLMSG_SPACE(sizeof(struct iscsi_uevent) + | 772 | NLMSG_SPACE(sizeof(struct iscsi_uevent) + |
@@ -800,14 +788,13 @@ iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev) | |||
800 | goto free_pdu_pool; | 788 | goto free_pdu_pool; |
801 | } | 789 | } |
802 | 790 | ||
803 | ev->r.handle = conn->connh = iscsi_handle(conn->dd_data); | 791 | ev->r.handle = iscsi_handle(conn); |
804 | 792 | ||
805 | spin_lock_irqsave(&connlock, flags); | 793 | spin_lock_irqsave(&connlock, flags); |
806 | list_add(&conn->conn_list, &connlist); | 794 | list_add(&conn->conn_list, &connlist); |
807 | conn->active = 1; | 795 | conn->active = 1; |
808 | spin_unlock_irqrestore(&connlock, flags); | 796 | spin_unlock_irqrestore(&connlock, flags); |
809 | 797 | ||
810 | scsi_host_put(shost); | ||
811 | return 0; | 798 | return 0; |
812 | 799 | ||
813 | free_pdu_pool: | 800 | free_pdu_pool: |
@@ -815,8 +802,6 @@ free_pdu_pool: | |||
815 | destroy_conn: | 802 | destroy_conn: |
816 | if (transport->destroy_conn) | 803 | if (transport->destroy_conn) |
817 | transport->destroy_conn(conn->dd_data); | 804 | transport->destroy_conn(conn->dd_data); |
818 | release_ref: | ||
819 | scsi_host_put(shost); | ||
820 | return -ENOMEM; | 805 | return -ENOMEM; |
821 | } | 806 | } |
822 | 807 | ||
@@ -827,13 +812,9 @@ iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev | |||
827 | struct iscsi_cls_conn *conn; | 812 | struct iscsi_cls_conn *conn; |
828 | struct mempool_zone *z_error, *z_pdu; | 813 | struct mempool_zone *z_error, *z_pdu; |
829 | 814 | ||
830 | conn = iscsi_if_find_conn(ev->u.d_conn.conn_handle); | 815 | conn = iscsi_conn_lookup(ev->u.d_conn.conn_handle); |
831 | if (!conn) | 816 | if (!conn) |
832 | return -EEXIST; | ||
833 | |||
834 | if (!transport->destroy_conn) | ||
835 | return -EINVAL; | 817 | return -EINVAL; |
836 | |||
837 | spin_lock_irqsave(&connlock, flags); | 818 | spin_lock_irqsave(&connlock, flags); |
838 | conn->active = 0; | 819 | conn->active = 0; |
839 | list_del(&conn->conn_list); | 820 | list_del(&conn->conn_list); |
@@ -858,23 +839,27 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
858 | struct iscsi_uevent *ev = NLMSG_DATA(nlh); | 839 | struct iscsi_uevent *ev = NLMSG_DATA(nlh); |
859 | struct iscsi_transport *transport = NULL; | 840 | struct iscsi_transport *transport = NULL; |
860 | struct iscsi_internal *priv; | 841 | struct iscsi_internal *priv; |
861 | 842 | struct iscsi_cls_session *session; | |
862 | if (NETLINK_CREDS(skb)->uid) | 843 | struct iscsi_cls_conn *conn; |
863 | return -EPERM; | ||
864 | 844 | ||
865 | priv = iscsi_if_transport_lookup(iscsi_ptr(ev->transport_handle)); | 845 | priv = iscsi_if_transport_lookup(iscsi_ptr(ev->transport_handle)); |
866 | if (!priv) | 846 | if (!priv) |
867 | return -EINVAL; | 847 | return -EINVAL; |
868 | transport = priv->iscsi_transport; | 848 | transport = priv->iscsi_transport; |
869 | 849 | ||
870 | daemon_pid = NETLINK_CREDS(skb)->pid; | 850 | if (!try_module_get(transport->owner)) |
851 | return -EINVAL; | ||
871 | 852 | ||
872 | switch (nlh->nlmsg_type) { | 853 | switch (nlh->nlmsg_type) { |
873 | case ISCSI_UEVENT_CREATE_SESSION: | 854 | case ISCSI_UEVENT_CREATE_SESSION: |
874 | err = iscsi_if_create_session(priv, ev); | 855 | err = iscsi_if_create_session(priv, ev); |
875 | break; | 856 | break; |
876 | case ISCSI_UEVENT_DESTROY_SESSION: | 857 | case ISCSI_UEVENT_DESTROY_SESSION: |
877 | err = iscsi_if_destroy_session(priv, ev); | 858 | session = iscsi_session_lookup(ev->u.d_session.session_handle); |
859 | if (session) | ||
860 | transport->destroy_session(session); | ||
861 | else | ||
862 | err = -EINVAL; | ||
878 | break; | 863 | break; |
879 | case ISCSI_UEVENT_CREATE_CONN: | 864 | case ISCSI_UEVENT_CREATE_CONN: |
880 | err = iscsi_if_create_conn(transport, ev); | 865 | err = iscsi_if_create_conn(transport, ev); |
@@ -883,56 +868,64 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
883 | err = iscsi_if_destroy_conn(transport, ev); | 868 | err = iscsi_if_destroy_conn(transport, ev); |
884 | break; | 869 | break; |
885 | case ISCSI_UEVENT_BIND_CONN: | 870 | case ISCSI_UEVENT_BIND_CONN: |
886 | if (!iscsi_if_find_conn(ev->u.b_conn.conn_handle)) | 871 | session = iscsi_session_lookup(ev->u.b_conn.session_handle); |
887 | return -EEXIST; | 872 | conn = iscsi_conn_lookup(ev->u.b_conn.conn_handle); |
888 | ev->r.retcode = transport->bind_conn( | 873 | |
889 | ev->u.b_conn.session_handle, | 874 | if (session && conn) |
890 | ev->u.b_conn.conn_handle, | 875 | ev->r.retcode = transport->bind_conn(session, conn, |
891 | ev->u.b_conn.transport_fd, | 876 | ev->u.b_conn.transport_fd, |
892 | ev->u.b_conn.is_leading); | 877 | ev->u.b_conn.is_leading); |
878 | else | ||
879 | err = -EINVAL; | ||
893 | break; | 880 | break; |
894 | case ISCSI_UEVENT_SET_PARAM: | 881 | case ISCSI_UEVENT_SET_PARAM: |
895 | if (!iscsi_if_find_conn(ev->u.set_param.conn_handle)) | 882 | conn = iscsi_conn_lookup(ev->u.set_param.conn_handle); |
896 | return -EEXIST; | 883 | if (conn) |
897 | ev->r.retcode = transport->set_param( | 884 | ev->r.retcode = transport->set_param(conn, |
898 | ev->u.set_param.conn_handle, | 885 | ev->u.set_param.param, ev->u.set_param.value); |
899 | ev->u.set_param.param, ev->u.set_param.value); | 886 | else |
887 | err = -EINVAL; | ||
900 | break; | 888 | break; |
901 | case ISCSI_UEVENT_START_CONN: | 889 | case ISCSI_UEVENT_START_CONN: |
902 | if (!iscsi_if_find_conn(ev->u.start_conn.conn_handle)) | 890 | conn = iscsi_conn_lookup(ev->u.start_conn.conn_handle); |
903 | return -EEXIST; | 891 | if (conn) |
904 | ev->r.retcode = transport->start_conn( | 892 | ev->r.retcode = transport->start_conn(conn); |
905 | ev->u.start_conn.conn_handle); | 893 | else |
894 | err = -EINVAL; | ||
895 | |||
906 | break; | 896 | break; |
907 | case ISCSI_UEVENT_STOP_CONN: | 897 | case ISCSI_UEVENT_STOP_CONN: |
908 | if (!iscsi_if_find_conn(ev->u.stop_conn.conn_handle)) | 898 | conn = iscsi_conn_lookup(ev->u.stop_conn.conn_handle); |
909 | return -EEXIST; | 899 | if (conn) |
910 | transport->stop_conn(ev->u.stop_conn.conn_handle, | 900 | transport->stop_conn(conn, ev->u.stop_conn.flag); |
911 | ev->u.stop_conn.flag); | 901 | else |
902 | err = -EINVAL; | ||
912 | break; | 903 | break; |
913 | case ISCSI_UEVENT_SEND_PDU: | 904 | case ISCSI_UEVENT_SEND_PDU: |
914 | if (!iscsi_if_find_conn(ev->u.send_pdu.conn_handle)) | 905 | conn = iscsi_conn_lookup(ev->u.send_pdu.conn_handle); |
915 | return -EEXIST; | 906 | if (conn) |
916 | ev->r.retcode = transport->send_pdu( | 907 | ev->r.retcode = transport->send_pdu(conn, |
917 | ev->u.send_pdu.conn_handle, | 908 | (struct iscsi_hdr*)((char*)ev + sizeof(*ev)), |
918 | (struct iscsi_hdr*)((char*)ev + sizeof(*ev)), | 909 | (char*)ev + sizeof(*ev) + ev->u.send_pdu.hdr_size, |
919 | (char*)ev + sizeof(*ev) + ev->u.send_pdu.hdr_size, | 910 | ev->u.send_pdu.data_size); |
920 | ev->u.send_pdu.data_size); | 911 | else |
912 | err = -EINVAL; | ||
921 | break; | 913 | break; |
922 | case ISCSI_UEVENT_GET_STATS: | 914 | case ISCSI_UEVENT_GET_STATS: |
923 | err = iscsi_if_get_stats(transport, skb, nlh); | 915 | err = iscsi_if_get_stats(transport, nlh); |
924 | break; | 916 | break; |
925 | default: | 917 | default: |
926 | err = -EINVAL; | 918 | err = -EINVAL; |
927 | break; | 919 | break; |
928 | } | 920 | } |
929 | 921 | ||
922 | module_put(transport->owner); | ||
930 | return err; | 923 | return err; |
931 | } | 924 | } |
932 | 925 | ||
933 | /* Get message from skb (based on rtnetlink_rcv_skb). Each message is | 926 | /* Get message from skb (based on rtnetlink_rcv_skb). Each message is |
934 | * processed by iscsi_if_recv_msg. Malformed skbs with wrong length are | 927 | * processed by iscsi_if_recv_msg. Malformed skbs with wrong length are |
935 | * discarded silently. */ | 928 | * or invalid creds discarded silently. */ |
936 | static void | 929 | static void |
937 | iscsi_if_rx(struct sock *sk, int len) | 930 | iscsi_if_rx(struct sock *sk, int len) |
938 | { | 931 | { |
@@ -940,6 +933,12 @@ iscsi_if_rx(struct sock *sk, int len) | |||
940 | 933 | ||
941 | mutex_lock(&rx_queue_mutex); | 934 | mutex_lock(&rx_queue_mutex); |
942 | while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) { | 935 | while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) { |
936 | if (NETLINK_CREDS(skb)->uid) { | ||
937 | skb_pull(skb, skb->len); | ||
938 | goto free_skb; | ||
939 | } | ||
940 | daemon_pid = NETLINK_CREDS(skb)->pid; | ||
941 | |||
943 | while (skb->len >= NLMSG_SPACE(0)) { | 942 | while (skb->len >= NLMSG_SPACE(0)) { |
944 | int err; | 943 | int err; |
945 | uint32_t rlen; | 944 | uint32_t rlen; |
@@ -951,10 +950,12 @@ iscsi_if_rx(struct sock *sk, int len) | |||
951 | skb->len < nlh->nlmsg_len) { | 950 | skb->len < nlh->nlmsg_len) { |
952 | break; | 951 | break; |
953 | } | 952 | } |
953 | |||
954 | ev = NLMSG_DATA(nlh); | 954 | ev = NLMSG_DATA(nlh); |
955 | rlen = NLMSG_ALIGN(nlh->nlmsg_len); | 955 | rlen = NLMSG_ALIGN(nlh->nlmsg_len); |
956 | if (rlen > skb->len) | 956 | if (rlen > skb->len) |
957 | rlen = skb->len; | 957 | rlen = skb->len; |
958 | |||
958 | err = iscsi_if_recv_msg(skb, nlh); | 959 | err = iscsi_if_recv_msg(skb, nlh); |
959 | if (err) { | 960 | if (err) { |
960 | ev->type = ISCSI_KEVENT_IF_ERROR; | 961 | ev->type = ISCSI_KEVENT_IF_ERROR; |
@@ -978,6 +979,7 @@ iscsi_if_rx(struct sock *sk, int len) | |||
978 | } while (err < 0 && err != -ECONNREFUSED); | 979 | } while (err < 0 && err != -ECONNREFUSED); |
979 | skb_pull(skb, rlen); | 980 | skb_pull(skb, rlen); |
980 | } | 981 | } |
982 | free_skb: | ||
981 | kfree_skb(skb); | 983 | kfree_skb(skb); |
982 | } | 984 | } |
983 | mutex_unlock(&rx_queue_mutex); | 985 | mutex_unlock(&rx_queue_mutex); |
@@ -997,7 +999,7 @@ show_conn_int_param_##param(struct class_device *cdev, char *buf) \ | |||
997 | struct iscsi_cls_conn *conn = iscsi_cdev_to_conn(cdev); \ | 999 | struct iscsi_cls_conn *conn = iscsi_cdev_to_conn(cdev); \ |
998 | struct iscsi_transport *t = conn->transport; \ | 1000 | struct iscsi_transport *t = conn->transport; \ |
999 | \ | 1001 | \ |
1000 | t->get_conn_param(conn->dd_data, param, &value); \ | 1002 | t->get_conn_param(conn, param, &value); \ |
1001 | return snprintf(buf, 20, format"\n", value); \ | 1003 | return snprintf(buf, 20, format"\n", value); \ |
1002 | } | 1004 | } |
1003 | 1005 | ||
@@ -1024,10 +1026,9 @@ show_session_int_param_##param(struct class_device *cdev, char *buf) \ | |||
1024 | { \ | 1026 | { \ |
1025 | uint32_t value = 0; \ | 1027 | uint32_t value = 0; \ |
1026 | struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev); \ | 1028 | struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev); \ |
1027 | struct Scsi_Host *shost = iscsi_session_to_shost(session); \ | ||
1028 | struct iscsi_transport *t = session->transport; \ | 1029 | struct iscsi_transport *t = session->transport; \ |
1029 | \ | 1030 | \ |
1030 | t->get_session_param(shost, param, &value); \ | 1031 | t->get_session_param(session, param, &value); \ |
1031 | return snprintf(buf, 20, format"\n", value); \ | 1032 | return snprintf(buf, 20, format"\n", value); \ |
1032 | } | 1033 | } |
1033 | 1034 | ||
@@ -1121,7 +1122,6 @@ iscsi_register_transport(struct iscsi_transport *tt) | |||
1121 | return NULL; | 1122 | return NULL; |
1122 | memset(priv, 0, sizeof(*priv)); | 1123 | memset(priv, 0, sizeof(*priv)); |
1123 | INIT_LIST_HEAD(&priv->list); | 1124 | INIT_LIST_HEAD(&priv->list); |
1124 | INIT_LIST_HEAD(&priv->sessions); | ||
1125 | priv->iscsi_transport = tt; | 1125 | priv->iscsi_transport = tt; |
1126 | 1126 | ||
1127 | priv->cdev.class = &iscsi_transport_class; | 1127 | priv->cdev.class = &iscsi_transport_class; |