mirror of
https://github.com/SCST-project/scst.git
synced 2026-05-26 00:10:19 +00:00
Conflicts: Makefile fcst/Makefile iscsi-scst/Makefile iscsi-scst/include/iscsi_scst.h iscsi-scst/include/iscsi_scst_ver.h iscsi-scst/kernel/Makefile iscsi-scst/kernel/config.c iscsi-scst/kernel/conn.c iscsi-scst/kernel/digest.c iscsi-scst/kernel/digest.h iscsi-scst/kernel/event.c iscsi-scst/kernel/iscsi.c iscsi-scst/kernel/iscsi.h iscsi-scst/kernel/iscsi_dbg.h iscsi-scst/kernel/iscsi_hdr.h iscsi-scst/kernel/nthread.c iscsi-scst/kernel/param.c iscsi-scst/kernel/session.c iscsi-scst/kernel/target.c iscsi-scst/usr/Makefile iscsi-scst/usr/chap.c iscsi-scst/usr/config.c iscsi-scst/usr/conn.c iscsi-scst/usr/ctldev.c iscsi-scst/usr/event.c iscsi-scst/usr/iscsi_adm.c iscsi-scst/usr/iscsi_adm.h iscsi-scst/usr/iscsi_hdr.h iscsi-scst/usr/iscsi_scstd.c iscsi-scst/usr/iscsid.c iscsi-scst/usr/iscsid.h iscsi-scst/usr/isns.c iscsi-scst/usr/isns_proto.h iscsi-scst/usr/log.c iscsi-scst/usr/message.c iscsi-scst/usr/misc.c iscsi-scst/usr/misc.h iscsi-scst/usr/param.c iscsi-scst/usr/param.h iscsi-scst/usr/session.c iscsi-scst/usr/target.c iscsi-scst/usr/types.h nightly/conf/nightly.conf qla2x00t/qla2x00-target/Makefile qla2x00t/qla2x00-target/README qla2x00t/qla2x00-target/qla2x00t.c qla2x00t/qla2x00-target/qla2x00t.h qla2x00t/qla2x_tgt.h qla2x00t/qla2x_tgt_def.h qla2x00t/qla_attr.c qla2x00t/qla_init.c qla2x00t/qla_inline.h qla2x00t/qla_isr.c qla2x00t/qla_mbx.c qla2x00t/qla_os.c scripts/generate-release-archive scripts/rebuild-rhel-kernel-rpm scripts/run-regression-tests scst.spec.in scst/Makefile scst/README scst/README_in-tree scst/include/scst.h scst/include/scst_const.h scst/include/scst_debug.h scst/include/scst_sgv.h scst/include/scst_user.h scst/src/Makefile scst/src/dev_handlers/Makefile scst/src/dev_handlers/scst_cdrom.c scst/src/dev_handlers/scst_changer.c scst/src/dev_handlers/scst_disk.c scst/src/dev_handlers/scst_modisk.c scst/src/dev_handlers/scst_processor.c scst/src/dev_handlers/scst_raid.c scst/src/dev_handlers/scst_tape.c scst/src/dev_handlers/scst_user.c scst/src/dev_handlers/scst_vdisk.c scst/src/scst_debug.c scst/src/scst_lib.c scst/src/scst_main.c scst/src/scst_mem.c scst/src/scst_mem.h scst/src/scst_module.c scst/src/scst_pres.c scst/src/scst_pres.h scst/src/scst_priv.h scst/src/scst_proc.c scst/src/scst_sysfs.c scst/src/scst_targ.c scst/src/scst_tg.c scst_local/scst_local.c srpt/Makefile srpt/README srpt/README.ofed srpt/conftest/gid_change/Makefile srpt/src/ib_srpt.c srpt/src/ib_srpt.h usr/fileio/Makefile usr/fileio/common.c usr/fileio/common.h usr/fileio/debug.c usr/fileio/debug.h usr/fileio/fileio.c www/comparison.html www/contributing.html www/downloads.html www/handler_fileio_tgt.html www/index.html www/mc_s.html www/scst_admin.html www/scstvslio.html www/scstvsstgt.html www/solutions.html www/target_emulex.html www/target_fcoe.html www/target_ibmvscsi.html www/target_iscsi.html www/target_local.html www/target_lsi.html www/target_mvsas.html www/target_old.html www/target_qla2x00t.html www/target_srp.html www/targets.html www/users.html
122 lines
2.8 KiB
C
122 lines
2.8 KiB
C
/*
|
|
* Copyright (C) 2007 - 2015 Vladislav Bolkhovitin
|
|
* Copyright (C) 2007 - 2015 SanDisk Corporation
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation, version 2
|
|
* of the License.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
#include <fcntl.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/tcp.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
|
|
#include "iscsid.h"
|
|
|
|
int create_and_open_dev(const char *dev, int readonly)
|
|
{
|
|
FILE *f;
|
|
char devname[256];
|
|
char buf[256];
|
|
int devn;
|
|
int ctlfd = -1;
|
|
int err;
|
|
int flags;
|
|
|
|
f = fopen("/proc/devices", "r");
|
|
if (!f) {
|
|
err = -errno;
|
|
perror("Cannot open control path to the driver");
|
|
goto out;
|
|
}
|
|
|
|
devn = 0;
|
|
while (!feof(f)) {
|
|
if (!fgets(buf, sizeof(buf), f))
|
|
break;
|
|
if (sscanf(buf, "%d %s", &devn, devname) != 2)
|
|
continue;
|
|
if (!strcmp(devname, dev))
|
|
break;
|
|
devn = 0;
|
|
}
|
|
|
|
fclose(f);
|
|
if (!devn) {
|
|
err = -ENOENT;
|
|
printf("cannot find %s in /proc/devices - "
|
|
"make sure the module is loaded\n", dev);
|
|
goto out;
|
|
}
|
|
|
|
sprintf(devname, "/dev/%s", dev);
|
|
|
|
unlink(devname);
|
|
if (mknod(devname, (S_IFCHR | 0600), (devn << 8))) {
|
|
err = -errno;
|
|
printf("cannot create %s %s\n", devname, strerror(errno));
|
|
goto out;
|
|
}
|
|
|
|
if (readonly)
|
|
flags = O_RDONLY;
|
|
else
|
|
flags = O_RDWR;
|
|
|
|
err = ctlfd = open(devname, flags);
|
|
if (ctlfd < 0) {
|
|
err = -errno;
|
|
printf("cannot open %s %s\n", devname, strerror(errno));
|
|
goto out;
|
|
}
|
|
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
void set_non_blocking(int fd)
|
|
{
|
|
int res = fcntl(fd, F_GETFL);
|
|
|
|
if (res != -1) {
|
|
res = fcntl(fd, F_SETFL, res | O_NONBLOCK);
|
|
if (res)
|
|
log_warning("unable to set fd flags (%s)!", strerror(errno));
|
|
} else
|
|
log_warning("unable to get fd flags (%s)!", strerror(errno));
|
|
}
|
|
|
|
void sock_set_keepalive(int sock, int timeout)
|
|
{
|
|
if (timeout) { /* timeout [s] */
|
|
int opt = 2;
|
|
|
|
if (setsockopt(sock, SOL_TCP, TCP_KEEPCNT, &opt, sizeof(opt)))
|
|
log_warning("unable to set TCP_KEEPCNT on server socket (%s)!", strerror(errno));
|
|
|
|
if (setsockopt(sock, SOL_TCP, TCP_KEEPIDLE, &timeout, sizeof(timeout)))
|
|
log_warning("unable to set TCP_KEEPIDLE on server socket (%s)!", strerror(errno));
|
|
|
|
opt = 3;
|
|
if (setsockopt(sock, SOL_TCP, TCP_KEEPINTVL, &opt, sizeof(opt)))
|
|
log_warning("unable to set KEEPINTVL on server socket (%s)!", strerror(errno));
|
|
|
|
opt = 1;
|
|
if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt)))
|
|
log_warning("unable to set SO_KEEPALIVE on server socket (%s)!", strerror(errno));
|
|
}
|
|
}
|
|
|