From 3625bde45d09846239060e275d79331c8ed67e92 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Wed, 9 Oct 2013 18:39:44 +0000 Subject: [PATCH 01/13] Reduce code duplication, introduce the getmaxfd() helper to calculate the max filedescriptor index. Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Approved by: re (marius) --- sys/kern/kern_descrip.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index a1021e12c13..6bf0c6051a0 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -129,6 +129,7 @@ static int fill_sem_info(struct file *fp, struct kinfo_file *kif); static int fill_shm_info(struct file *fp, struct kinfo_file *kif); static int fill_socket_info(struct socket *so, struct kinfo_file *kif); static int fill_vnode_info(struct vnode *vp, struct kinfo_file *kif); +static int getmaxfd(struct proc *p); /* * Each process has: @@ -771,6 +772,18 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) return (error); } +static int +getmaxfd(struct proc *p) +{ + int maxfd; + + PROC_LOCK(p); + maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc); + PROC_UNLOCK(p); + + return (maxfd); +} + /* * Common code for dup, dup2, fcntl(F_DUPFD) and fcntl(F_DUP2FD). */ @@ -797,9 +810,7 @@ do_dup(struct thread *td, int flags, int old, int new, return (EBADF); if (new < 0) return (flags & DUP_FCNTL ? EINVAL : EBADF); - PROC_LOCK(p); - maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc); - PROC_UNLOCK(p); + maxfd = getmaxfd(p); if (new >= maxfd) return (flags & DUP_FCNTL ? EINVAL : EBADF); @@ -1563,9 +1574,7 @@ fdalloc(struct thread *td, int minfd, int *result) if (fdp->fd_freefile > minfd) minfd = fdp->fd_freefile; - PROC_LOCK(p); - maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc); - PROC_UNLOCK(p); + maxfd = getmaxfd(p); /* * Search the bitmap for a free descriptor starting at minfd. @@ -1652,9 +1661,7 @@ fdavail(struct thread *td, int n) * call racct_add() from there instead of dealing with containers * here. */ - PROC_LOCK(p); - lim = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc); - PROC_UNLOCK(p); + lim = getmaxfd(p); if ((i = lim - fdp->fd_nfiles) > 0 && (n -= i) <= 0) return (1); last = min(fdp->fd_nfiles, lim); From 1744fe5048d9a1212d0eb5ae7b44d5125766c1d1 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Wed, 9 Oct 2013 18:41:35 +0000 Subject: [PATCH 02/13] When growing the file descriptor table, new larger memory chunk is allocated, but the old table is kept around to handle the case of threads still performing unlocked accesses to it. Grow the table exponentially instead of increasing its size by sizeof(long) * 8 chunks when overflowing. This mode significantly reduces the total memory use for the processes consuming large numbers of the file descriptors which open them one by one. Reported and tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Approved by: re (marius) --- sys/kern/kern_descrip.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 6bf0c6051a0..c1f0d384073 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -119,6 +119,7 @@ static int closefp(struct filedesc *fdp, int fd, struct file *fp, static int fd_first_free(struct filedesc *fdp, int low, int size); static int fd_last_used(struct filedesc *fdp, int size); static void fdgrowtable(struct filedesc *fdp, int nfd); +static void fdgrowtable_exp(struct filedesc *fdp, int nfd); static void fdunused(struct filedesc *fdp, int fd); static void fdused(struct filedesc *fdp, int fd); static int fill_pipe_info(struct pipe *pi, struct kinfo_file *kif); @@ -855,7 +856,7 @@ do_dup(struct thread *td, int flags, int old, int new, return (EMFILE); } #endif - fdgrowtable(fdp, new + 1); + fdgrowtable_exp(fdp, new + 1); oldfde = &fdp->fd_ofiles[old]; } newfde = &fdp->fd_ofiles[new]; @@ -1478,6 +1479,24 @@ filecaps_validate(const struct filecaps *fcaps, const char *func) ("%s: ioctls without CAP_IOCTL", func)); } +static void +fdgrowtable_exp(struct filedesc *fdp, int nfd) +{ + int nfd1, maxfd; + + FILEDESC_XLOCK_ASSERT(fdp); + + nfd1 = fdp->fd_nfiles * 2; + if (nfd1 < nfd) + nfd1 = nfd; + maxfd = getmaxfd(curproc); + if (maxfd < nfd1) + nfd1 = maxfd; + KASSERT(nfd <= nfd1, + ("too low nfd1 %d %d %d %d", nfd, fdp->fd_nfiles, maxfd, nfd1)); + fdgrowtable(fdp, nfd1); +} + /* * Grow the file table to accomodate (at least) nfd descriptors. */ @@ -1596,7 +1615,7 @@ fdalloc(struct thread *td, int minfd, int *result) * fd is already equal to first free descriptor >= minfd, so * we only need to grow the table and we are done. */ - fdgrowtable(fdp, allocfd); + fdgrowtable_exp(fdp, allocfd); } /* From 2c1531e746a13846e4c2000fb4ec23dc490da4b8 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Wed, 9 Oct 2013 18:43:29 +0000 Subject: [PATCH 03/13] Do not flush buffers when the v_object of the passed vnode does not really belong to it. Such vnodes, with the pointers to other vnodes v_objects, are typically instantiated by the bypass filesystems. Invalidating mappings of other vnode pages and the pages is wrong, since reclamation of the upper vnode does not imply that lower vnode is reclaimed too. One of the consequences of the improper reclamation was destruction of the wired mappings of the lower vnode pages, triggering miscellaneous assertions in the VM system. Reported by: John Marshall Tested by: John Marshall , pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Approved by: re (gjb) --- sys/kern/vfs_subr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 930a3c8f478..91c64a301b9 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1315,6 +1315,8 @@ vinvalbuf(struct vnode *vp, int flags, int slpflag, int slptimeo) CTR3(KTR_VFS, "%s: vp %p with flags %d", __func__, vp, flags); ASSERT_VOP_LOCKED(vp, "vinvalbuf"); + if (vp->v_object != NULL && vp->v_object->handle != vp) + return (0); return (bufobj_invalbuf(&vp->v_bufobj, flags, slpflag, slptimeo)); } From acb9d2c7f022fc412e3618b7a4c18546f8903b0b Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Wed, 9 Oct 2013 18:45:01 +0000 Subject: [PATCH 04/13] The device vnodes are often unlocked when bread() or bwrite() is called. This probably should be fixed eventually, but for now it is not needed to try to flush such vnodes from the buffer allocation context. Reported and tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Approved by: re (gjb) --- sys/kern/vfs_bio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 1690ee5a05e..362de37e8aa 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -2076,7 +2076,8 @@ getnewbuf_bufd_help(struct vnode *vp, int gbflags, int slpflag, int slptimeo, wait = MNT_NOWAIT; mtx_lock(&nblock); while (needsbuffer & flags) { - if (vp != NULL && (td->td_pflags & TDP_BUFNEED) == 0) { + if (vp != NULL && vp->v_type != VCHR && + (td->td_pflags & TDP_BUFNEED) == 0) { mtx_unlock(&nblock); /* From 4cdc1f5421c5e44b6004e9f4bb1f98dc034bde52 Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Wed, 9 Oct 2013 19:04:40 +0000 Subject: [PATCH 05/13] There are some high performance NICs that count statistics in hardware, and there are ifnets, that do that via counter(9). Provide a flag that would skip cache line trashing '+=' operation in ether_input(). Sponsored by: Netflix Sponsored by: Nginx, Inc. Reviewed by: melifaro, adrian Approved by: re (marius) --- sys/dev/cxgbe/t4_main.c | 2 +- sys/dev/ixgbe/ixgbe.c | 3 ++- sys/net/if.h | 1 + sys/net/if_ethersubr.c | 3 ++- sys/net/if_lagg.c | 1 + 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sys/dev/cxgbe/t4_main.c b/sys/dev/cxgbe/t4_main.c index d905cd5aabd..c46ed5a066d 100644 --- a/sys/dev/cxgbe/t4_main.c +++ b/sys/dev/cxgbe/t4_main.c @@ -950,7 +950,7 @@ cxgbe_probe(device_t dev) #define T4_CAP (IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU | IFCAP_HWCSUM | \ IFCAP_VLAN_HWCSUM | IFCAP_TSO | IFCAP_JUMBO_MTU | IFCAP_LRO | \ - IFCAP_VLAN_HWTSO | IFCAP_LINKSTATE | IFCAP_HWCSUM_IPV6) + IFCAP_VLAN_HWTSO | IFCAP_LINKSTATE | IFCAP_HWCSUM_IPV6 | IFCAP_HWSTATS) #define T4_CAP_ENABLE (T4_CAP) static int diff --git a/sys/dev/ixgbe/ixgbe.c b/sys/dev/ixgbe/ixgbe.c index 3434125fc48..e913bd5eec5 100644 --- a/sys/dev/ixgbe/ixgbe.c +++ b/sys/dev/ixgbe/ixgbe.c @@ -2662,7 +2662,8 @@ ixgbe_setup_interface(device_t dev, struct adapter *adapter) ifp->if_capabilities |= IFCAP_LRO; ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWTSO - | IFCAP_VLAN_MTU; + | IFCAP_VLAN_MTU + | IFCAP_HWSTATS; ifp->if_capenable = ifp->if_capabilities; /* diff --git a/sys/net/if.h b/sys/net/if.h index ab98ec0b282..80a7112678d 100644 --- a/sys/net/if.h +++ b/sys/net/if.h @@ -231,6 +231,7 @@ struct if_data { #define IFCAP_NETMAP 0x100000 /* netmap mode supported/enabled */ #define IFCAP_RXCSUM_IPV6 0x200000 /* can offload checksum on IPv6 RX */ #define IFCAP_TXCSUM_IPV6 0x400000 /* can offload checksum on IPv6 TX */ +#define IFCAP_HWSTATS 0x800000 /* manages counters internally */ #define IFCAP_HWCSUM_IPV6 (IFCAP_RXCSUM_IPV6 | IFCAP_TXCSUM_IPV6) diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index 638b3647f6b..d5c55219817 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -528,7 +528,8 @@ ether_input_internal(struct ifnet *ifp, struct mbuf *m) m->m_flags &= ~M_HASFCS; } - ifp->if_ibytes += m->m_pkthdr.len; + if (!(ifp->if_capenable & IFCAP_HWSTATS)) + ifp->if_ibytes += m->m_pkthdr.len; /* Allow monitor mode to claim this frame, after stats are updated. */ if (ifp->if_flags & IFF_MONITOR) { diff --git a/sys/net/if_lagg.c b/sys/net/if_lagg.c index 27bab876faf..258c2f9113a 100644 --- a/sys/net/if_lagg.c +++ b/sys/net/if_lagg.c @@ -347,6 +347,7 @@ lagg_clone_create(struct if_clone *ifc, int unit, caddr_t params) ifp->if_init = lagg_init; ifp->if_ioctl = lagg_ioctl; ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST; + ifp->if_capenable = ifp->if_capabilities = IFCAP_HWSTATS; /* * Attach as an ordinary ethernet device, children will be attached From e49b31f292877288dd9b7e6344bd88ea1e4b459c Mon Sep 17 00:00:00 2001 From: Edward Tomasz Napierala Date: Wed, 9 Oct 2013 19:28:56 +0000 Subject: [PATCH 06/13] Fail connection upon receiving too large data segment. Approved by: re (glebius) Sponsored by: FreeBSD Foundation --- sys/dev/iscsi/icl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/dev/iscsi/icl.c b/sys/dev/iscsi/icl.c index 67968783a96..cf58dfdb0c4 100644 --- a/sys/dev/iscsi/icl.c +++ b/sys/dev/iscsi/icl.c @@ -564,6 +564,7 @@ icl_conn_receive_pdu(struct icl_conn *ic, size_t *availablep) "MaxDataSegmentLength %zd; " "dropping connection", len, ic->ic_max_data_segment_length); + error = EINVAL; break; } From d43c9ec118a1690b6decfc8a97c071f3b6b76f11 Mon Sep 17 00:00:00 2001 From: Edward Tomasz Napierala Date: Wed, 9 Oct 2013 19:30:13 +0000 Subject: [PATCH 07/13] Be extra paranoid with values obtained from the target. Approved by: re (glebius) Sponsored by: FreeBSD Foundation --- sys/dev/iscsi/iscsi.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/sys/dev/iscsi/iscsi.c b/sys/dev/iscsi/iscsi.c index 2d347f3d884..3004777a45e 100644 --- a/sys/dev/iscsi/iscsi.c +++ b/sys/dev/iscsi/iscsi.c @@ -950,18 +950,16 @@ iscsi_pdu_handle_data_in(struct icl_pdu *response) csio = &io->io_ccb->csio; - if (ntohl(bhsdi->bhsdi_buffer_offset) + data_segment_len > - csio->dxfer_len) { + if (io->io_received + data_segment_len > csio->dxfer_len) { ISCSI_SESSION_WARN(is, "oversize data segment (%zd bytes " - "at offset %d, buffer is %d)", - data_segment_len, ntohl(bhsdi->bhsdi_buffer_offset), - csio->dxfer_len); + "at offset %zd, buffer is %d)", + data_segment_len, io->io_received, csio->dxfer_len); icl_pdu_free(response); iscsi_session_reconnect(is); return; } - icl_pdu_get_data(response, 0, csio->data_ptr + ntohl(bhsdi->bhsdi_buffer_offset), data_segment_len); + icl_pdu_get_data(response, 0, csio->data_ptr + io->io_received, data_segment_len); io->io_received += data_segment_len; /* @@ -1033,8 +1031,24 @@ iscsi_pdu_handle_r2t(struct icl_pdu *response) */ io->io_datasn = 0; + off = ntohl(bhsr2t->bhsr2t_buffer_offset); + if (off > csio->dxfer_len) { + ISCSI_SESSION_WARN(is, "target requested invalid offset " + "%zd, buffer is is %d; reconnecting", off, csio->dxfer_len); + icl_pdu_free(response); + iscsi_session_reconnect(is); + return; + } + total_len = ntohl(bhsr2t->bhsr2t_desired_data_transfer_length); + if (total_len == 0 || total_len > csio->dxfer_len) { + ISCSI_SESSION_WARN(is, "target requested invalid length " + "%zd, buffer is %d; reconnecting", total_len, csio->dxfer_len); + icl_pdu_free(response); + iscsi_session_reconnect(is); + return; + } //ISCSI_SESSION_DEBUG(is, "r2t; off %zd, len %zd", off, total_len); @@ -1045,7 +1059,8 @@ iscsi_pdu_handle_r2t(struct icl_pdu *response) len = is->is_max_data_segment_length; if (off + len > csio->dxfer_len) { - ISCSI_SESSION_WARN(is, "bad off %zd, len %d", + ISCSI_SESSION_WARN(is, "target requested invalid " + "length/offset %zd, buffer is %d; reconnecting", off + len, csio->dxfer_len); icl_pdu_free(response); iscsi_session_reconnect(is); @@ -1068,8 +1083,11 @@ iscsi_pdu_handle_r2t(struct icl_pdu *response) bhsr2t->bhsr2t_target_transfer_tag; bhsdo->bhsdo_datasn = htonl(io->io_datasn++); bhsdo->bhsdo_buffer_offset = htonl(off); - error = icl_pdu_append_data(request, csio->data_ptr + off, len, M_NOWAIT); + error = icl_pdu_append_data(request, csio->data_ptr + off, len, + M_NOWAIT); if (error != 0) { + ISCSI_SESSION_WARN(is, "failed to allocate memory; " + "reconnecting"); icl_pdu_free(request); icl_pdu_free(response); iscsi_session_reconnect(is); From cce45f0b079764c42d8cde77a61370d4deb9dda6 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Wed, 9 Oct 2013 19:37:41 +0000 Subject: [PATCH 08/13] Improve logging around some of the isci(4) reset and recovery paths. Sponsored by: Intel Discussed with: scottl Approved by: re (marius) MFC after: 1 week --- sys/dev/isci/isci_io_request.c | 9 +++++++-- sys/dev/isci/isci_sysctl.c | 34 ++++++++++++++++++++++++++++++++ sys/dev/isci/isci_task_request.c | 15 +++++++++++--- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/sys/dev/isci/isci_io_request.c b/sys/dev/isci/isci_io_request.c index 4486f31d64d..d1f5afe8943 100644 --- a/sys/dev/isci/isci_io_request.c +++ b/sys/dev/isci/isci_io_request.c @@ -153,11 +153,16 @@ isci_io_request_complete(SCI_CONTROLLER_HANDLE_T scif_controller, case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED: isci_remote_device_reset(isci_remote_device, NULL); + ccb->ccb_h.status |= CAM_REQ_TERMIO; + isci_log_message(0, "ISCI", + "isci: bus=%x target=%x lun=%x cdb[0]=%x remote device reset required\n", + ccb->ccb_h.path_id, ccb->ccb_h.target_id, + ccb->ccb_h.target_lun, ccb->csio.cdb_io.cdb_bytes[0]); + break; - /* drop through */ case SCI_IO_FAILURE_TERMINATED: ccb->ccb_h.status |= CAM_REQ_TERMIO; - isci_log_message(1, "ISCI", + isci_log_message(0, "ISCI", "isci: bus=%x target=%x lun=%x cdb[0]=%x terminated\n", ccb->ccb_h.path_id, ccb->ccb_h.target_id, ccb->ccb_h.target_lun, ccb->csio.cdb_io.cdb_bytes[0]); diff --git a/sys/dev/isci/isci_sysctl.c b/sys/dev/isci/isci_sysctl.c index 6a22e389d3e..4623a8aa396 100644 --- a/sys/dev/isci/isci_sysctl.c +++ b/sys/dev/isci/isci_sysctl.c @@ -193,6 +193,35 @@ isci_sysctl_start_phy(SYSCTL_HANDLER_ARGS) return 0; } +static int +isci_sysctl_log_frozen_lun_masks(SYSCTL_HANDLER_ARGS) +{ + struct isci_softc *isci = (struct isci_softc *)arg1; + struct ISCI_REMOTE_DEVICE *device; + int32_t log_frozen_devices = 0; + int error, i, j; + + error = sysctl_handle_int(oidp, &log_frozen_devices, 0, req); + + if (error || log_frozen_devices == 0) + return (error); + + for (i = 0; i < isci->controller_count; i++) { + for (j = 0; j < SCI_MAX_REMOTE_DEVICES; j++) { + device = isci->controllers[i].remote_device[j]; + + if (device == NULL) + continue; + + device_printf(isci->device, + "controller %d device %3d frozen_lun_mask 0x%02x\n", + i, j, device->frozen_lun_mask); + } + } + + return (0); +} + void isci_sysctl_initialize(struct isci_softc *isci) { struct sysctl_ctx_list *sysctl_ctx = device_get_sysctl_ctx(isci->device); @@ -225,5 +254,10 @@ void isci_sysctl_initialize(struct isci_softc *isci) SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO, "start_phy", CTLTYPE_UINT| CTLFLAG_RW, isci, 0, isci_sysctl_start_phy, "IU", "Start PHY on a controller"); + + SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO, + "log_frozen_lun_masks", CTLTYPE_UINT| CTLFLAG_RW, isci, 0, + isci_sysctl_log_frozen_lun_masks, "IU", + "Log frozen lun masks to kernel log"); } diff --git a/sys/dev/isci/isci_task_request.c b/sys/dev/isci/isci_task_request.c index 4ad07319fc4..5d7f63d294b 100644 --- a/sys/dev/isci/isci_task_request.c +++ b/sys/dev/isci/isci_task_request.c @@ -194,11 +194,20 @@ isci_task_request_complete(SCI_CONTROLLER_HANDLE_T scif_controller, break; case SCI_TASK_FAILURE_INVALID_STATE: - case SCI_TASK_FAILURE_INSUFFICIENT_RESOURCES: - case SCI_FAILURE_TIMEOUT: retry_task = TRUE; isci_log_message(0, "ISCI", - "unhandled task completion code 0x%x\n", completion_status); + "task failure (invalid state) - retrying\n"); + break; + + case SCI_TASK_FAILURE_INSUFFICIENT_RESOURCES: + retry_task = TRUE; + isci_log_message(0, "ISCI", + "task failure (insufficient resources) - retrying\n"); + break; + + case SCI_FAILURE_TIMEOUT: + retry_task = TRUE; + isci_log_message(0, "ISCI", "task timeout - retrying\n"); break; case SCI_TASK_FAILURE: From 2d07d6bc02e951905098f17ca520ff0c218a230c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Wed, 9 Oct 2013 19:37:51 +0000 Subject: [PATCH 09/13] Explicitly pass the full path to the input file to sed. This unbreaks the WITHOUT_BMAKE build. Approved by: re (gjb) --- libexec/freebsd-version/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/freebsd-version/Makefile b/libexec/freebsd-version/Makefile index 96685c43788..c4d6e7f1a27 100644 --- a/libexec/freebsd-version/Makefile +++ b/libexec/freebsd-version/Makefile @@ -7,7 +7,7 @@ CLEANFILES = freebsd-version.sh NEWVERS = ${.CURDIR}/../../sys/conf/newvers.sh freebsd-version.sh.in: ${NEWVERS} -freebsd-version.sh: freebsd-version.sh.in +freebsd-version.sh: ${.CURDIR}/freebsd-version.sh.in eval $$(egrep '^(TYPE|REVISION|BRANCH)=' ${NEWVERS}) ; \ if ! sed -e "\ s/@@TYPE@@/$${TYPE}/g; \ From 5239e66cc2e4d55d9166b5ebc2264cdfce1372cd Mon Sep 17 00:00:00 2001 From: Joel Dahl Date: Wed, 9 Oct 2013 20:00:04 +0000 Subject: [PATCH 10/13] Fix missing . Approved by: re (blanket) --- usr.sbin/bhyveload/bhyveload.8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr.sbin/bhyveload/bhyveload.8 b/usr.sbin/bhyveload/bhyveload.8 index 2c0edace904..2efcad0684b 100644 --- a/usr.sbin/bhyveload/bhyveload.8 +++ b/usr.sbin/bhyveload/bhyveload.8 @@ -1,4 +1,4 @@ -\" +.\" .\" Copyright (c) 2012 NetApp Inc .\" All rights reserved. .\" From 69647b7bcdb4cdb8fb6690d9db23ee3f883f2f09 Mon Sep 17 00:00:00 2001 From: Edward Tomasz Napierala Date: Wed, 9 Oct 2013 20:09:58 +0000 Subject: [PATCH 11/13] Properly handle residual count in Data-In PDUs with S bit set. Approved by: re (gjb) Sponsored by: FreeBSD Foundation --- sys/dev/iscsi/iscsi.c | 49 ++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/sys/dev/iscsi/iscsi.c b/sys/dev/iscsi/iscsi.c index 3004777a45e..1e65416b2aa 100644 --- a/sys/dev/iscsi/iscsi.c +++ b/sys/dev/iscsi/iscsi.c @@ -966,22 +966,43 @@ iscsi_pdu_handle_data_in(struct icl_pdu *response) * XXX: Check DataSN. * XXX: Check F. */ - if (bhsdi->bhsdi_flags & BHSDI_FLAGS_S) { - //ISCSI_SESSION_DEBUG(is, "got S flag; status 0x%x", bhsdi->bhsdi_status); - if (bhsdi->bhsdi_status == 0) { - io->io_ccb->ccb_h.status = CAM_REQ_CMP; - } else { - if ((io->io_ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) { - xpt_freeze_devq(io->io_ccb->ccb_h.path, 1); - ISCSI_SESSION_DEBUG(is, "freezing devq"); - } - io->io_ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR | CAM_DEV_QFRZN; - csio->scsi_status = bhsdi->bhsdi_status; - } - xpt_done(io->io_ccb); - iscsi_outstanding_remove(is, io); + if ((bhsdi->bhsdi_flags & BHSDI_FLAGS_S) == 0) { + /* + * Nothing more to do. + */ + icl_pdu_free(response); + return; } + //ISCSI_SESSION_DEBUG(is, "got S flag; status 0x%x", bhsdi->bhsdi_status); + if (bhsdi->bhsdi_status == 0) { + io->io_ccb->ccb_h.status = CAM_REQ_CMP; + } else { + if ((io->io_ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) { + xpt_freeze_devq(io->io_ccb->ccb_h.path, 1); + ISCSI_SESSION_DEBUG(is, "freezing devq"); + } + io->io_ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR | CAM_DEV_QFRZN; + csio->scsi_status = bhsdi->bhsdi_status; + } + + if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) { + KASSERT(io->io_received <= csio->dxfer_len, + ("io->io_received > csio->dxfer_len")); + if (io->io_received < csio->dxfer_len) { + csio->resid = ntohl(bhsdi->bhsdi_residual_count); + if (csio->resid != csio->dxfer_len - io->io_received) { + ISCSI_SESSION_WARN(is, "underflow mismatch: " + "target indicates %d, we calculated %zd", + csio->resid, + csio->dxfer_len - io->io_received); + } + csio->resid = csio->dxfer_len - io->io_received; + } + } + + xpt_done(io->io_ccb); + iscsi_outstanding_remove(is, io); icl_pdu_free(response); } From 5f3850777ee8731079cf7e375a90c10ec7a12058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Wed, 9 Oct 2013 20:47:20 +0000 Subject: [PATCH 12/13] By popular demand, move freebsd-version(1) from /libexec to /bin. Approved by: re (gjb) --- ObsoleteFiles.inc | 2 ++ bin/Makefile | 1 + {libexec => bin}/freebsd-version/Makefile | 1 - {libexec => bin}/freebsd-version/freebsd-version.1 | 4 ++-- {libexec => bin}/freebsd-version/freebsd-version.sh.in | 0 libexec/Makefile | 1 - 6 files changed, 5 insertions(+), 4 deletions(-) rename {libexec => bin}/freebsd-version/Makefile (96%) rename {libexec => bin}/freebsd-version/freebsd-version.1 (97%) rename {libexec => bin}/freebsd-version/freebsd-version.sh.in (100%) diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc index 9f3fbb9a848..e82f3b9bc02 100644 --- a/ObsoleteFiles.inc +++ b/ObsoleteFiles.inc @@ -38,6 +38,8 @@ # xargs -n1 | sort | uniq -d; # done +# 20131009: freebsd-version moved from /libexec to /bin +OLD_FILES+=/libexec/freebsd-version # 20131001: ar and ranlib from binutils not used OLD_FILES+=usr/bin/gnu-ar OLD_FILES+=usr/bin/gnu-ranlib diff --git a/bin/Makefile b/bin/Makefile index e5052cad51a..7b6a4ab8c8c 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -15,6 +15,7 @@ SUBDIR= cat \ echo \ ed \ expr \ + freebsd-version \ getfacl \ hostname \ kenv \ diff --git a/libexec/freebsd-version/Makefile b/bin/freebsd-version/Makefile similarity index 96% rename from libexec/freebsd-version/Makefile rename to bin/freebsd-version/Makefile index c4d6e7f1a27..0fe730860c2 100644 --- a/libexec/freebsd-version/Makefile +++ b/bin/freebsd-version/Makefile @@ -2,7 +2,6 @@ SCRIPTS = freebsd-version MAN = freebsd-version.1 -BINDIR = /libexec CLEANFILES = freebsd-version.sh NEWVERS = ${.CURDIR}/../../sys/conf/newvers.sh diff --git a/libexec/freebsd-version/freebsd-version.1 b/bin/freebsd-version/freebsd-version.1 similarity index 97% rename from libexec/freebsd-version/freebsd-version.1 rename to bin/freebsd-version/freebsd-version.1 index ee3f748f128..1eea5bbd972 100644 --- a/libexec/freebsd-version/freebsd-version.1 +++ b/bin/freebsd-version/freebsd-version.1 @@ -100,13 +100,13 @@ and the kernel. .Sh EXAMPLES To determine the version of the currently running userland: .Bd -literal -offset indent -/libexec/freebsd-version -u +/bin/freebsd-version -u .Ed .Pp To inspect a system being repaired using a live CD: .Bd -literal -offset indent mount -rt ufs /dev/ada0p2 /mnt -env ROOT=/mnt /mnt/libexec/freebsd-version -ku +env ROOT=/mnt /mnt/bin/freebsd-version -ku .Ed .Sh SEE ALSO .Xr uname 1 , diff --git a/libexec/freebsd-version/freebsd-version.sh.in b/bin/freebsd-version/freebsd-version.sh.in similarity index 100% rename from libexec/freebsd-version/freebsd-version.sh.in rename to bin/freebsd-version/freebsd-version.sh.in diff --git a/libexec/Makefile b/libexec/Makefile index 1039b24691d..0b9c9618a1b 100644 --- a/libexec/Makefile +++ b/libexec/Makefile @@ -8,7 +8,6 @@ SUBDIR= ${_atf} \ bootpd \ ${_comsat} \ fingerd \ - freebsd-version \ ftpd \ getty \ ${_mail.local} \ From 772f66457abf8907811c63af06afe7c7faac7d77 Mon Sep 17 00:00:00 2001 From: Pawel Jakub Dawidek Date: Wed, 9 Oct 2013 20:58:50 +0000 Subject: [PATCH 13/13] Handle the cases where NULL is passed as cap_rightsp to the filestat_new_entry() function. Reported by: Alex Kozlov Approved by: re (gjb) --- lib/libprocstat/libprocstat.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/libprocstat/libprocstat.c b/lib/libprocstat/libprocstat.c index 9056151e2b4..e1ec7af0fb2 100644 --- a/lib/libprocstat/libprocstat.c +++ b/lib/libprocstat/libprocstat.c @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #define _KERNEL #include #include @@ -395,7 +396,10 @@ filestat_new_entry(void *typedep, int type, int fd, int fflags, int uflags, entry->fs_ref_count = refcount; entry->fs_offset = offset; entry->fs_path = path; - entry->fs_cap_rights = *cap_rightsp; + if (cap_rightsp != NULL) + entry->fs_cap_rights = *cap_rightsp; + else + cap_rights_init(&entry->fs_cap_rights); return (entry); } @@ -478,21 +482,21 @@ procstat_getfiles_kvm(struct procstat *procstat, struct kinfo_proc *kp, int mmap /* root directory vnode, if one. */ if (filed.fd_rdir) { entry = filestat_new_entry(filed.fd_rdir, PS_FST_TYPE_VNODE, -1, - PS_FST_FFLAG_READ, PS_FST_UFLAG_RDIR, 0, 0, NULL, 0); + PS_FST_FFLAG_READ, PS_FST_UFLAG_RDIR, 0, 0, NULL, NULL); if (entry != NULL) STAILQ_INSERT_TAIL(head, entry, next); } /* current working directory vnode. */ if (filed.fd_cdir) { entry = filestat_new_entry(filed.fd_cdir, PS_FST_TYPE_VNODE, -1, - PS_FST_FFLAG_READ, PS_FST_UFLAG_CDIR, 0, 0, NULL, 0); + PS_FST_FFLAG_READ, PS_FST_UFLAG_CDIR, 0, 0, NULL, NULL); if (entry != NULL) STAILQ_INSERT_TAIL(head, entry, next); } /* jail root, if any. */ if (filed.fd_jdir) { entry = filestat_new_entry(filed.fd_jdir, PS_FST_TYPE_VNODE, -1, - PS_FST_FFLAG_READ, PS_FST_UFLAG_JAIL, 0, 0, NULL, 0); + PS_FST_FFLAG_READ, PS_FST_UFLAG_JAIL, 0, 0, NULL, NULL); if (entry != NULL) STAILQ_INSERT_TAIL(head, entry, next); } @@ -500,14 +504,14 @@ procstat_getfiles_kvm(struct procstat *procstat, struct kinfo_proc *kp, int mmap if (kp->ki_tracep) { entry = filestat_new_entry(kp->ki_tracep, PS_FST_TYPE_VNODE, -1, PS_FST_FFLAG_READ | PS_FST_FFLAG_WRITE, - PS_FST_UFLAG_TRACE, 0, 0, NULL, 0); + PS_FST_UFLAG_TRACE, 0, 0, NULL, NULL); if (entry != NULL) STAILQ_INSERT_TAIL(head, entry, next); } /* text vnode, if one */ if (kp->ki_textvp) { entry = filestat_new_entry(kp->ki_textvp, PS_FST_TYPE_VNODE, -1, - PS_FST_FFLAG_READ, PS_FST_UFLAG_TEXT, 0, 0, NULL, 0); + PS_FST_FFLAG_READ, PS_FST_UFLAG_TEXT, 0, 0, NULL, NULL); if (entry != NULL) STAILQ_INSERT_TAIL(head, entry, next); } @@ -515,7 +519,7 @@ procstat_getfiles_kvm(struct procstat *procstat, struct kinfo_proc *kp, int mmap if ((vp = getctty(kd, kp)) != NULL) { entry = filestat_new_entry(vp, PS_FST_TYPE_VNODE, -1, PS_FST_FFLAG_READ | PS_FST_FFLAG_WRITE, - PS_FST_UFLAG_CTTY, 0, 0, NULL, 0); + PS_FST_UFLAG_CTTY, 0, 0, NULL, NULL); if (entry != NULL) STAILQ_INSERT_TAIL(head, entry, next); } @@ -578,7 +582,7 @@ procstat_getfiles_kvm(struct procstat *procstat, struct kinfo_proc *kp, int mmap } /* XXXRW: No capability rights support for kvm yet. */ entry = filestat_new_entry(data, type, i, - to_filestat_flags(file.f_flag), 0, 0, 0, NULL, 0); + to_filestat_flags(file.f_flag), 0, 0, 0, NULL, NULL); if (entry != NULL) STAILQ_INSERT_TAIL(head, entry, next); } @@ -637,7 +641,7 @@ do_mmapped: */ entry = filestat_new_entry(object.handle, PS_FST_TYPE_VNODE, -1, fflags, - PS_FST_UFLAG_MMAP, 0, 0, NULL, 0); + PS_FST_UFLAG_MMAP, 0, 0, NULL, NULL); if (entry != NULL) STAILQ_INSERT_TAIL(head, entry, next); } @@ -878,7 +882,7 @@ procstat_getfiles_sysctl(struct procstat *procstat, struct kinfo_proc *kp, path = NULL; entry = filestat_new_entry(kve, PS_FST_TYPE_VNODE, -1, fflags, PS_FST_UFLAG_MMAP, refcount, offset, path, - 0); + NULL); if (entry != NULL) STAILQ_INSERT_TAIL(head, entry, next); }