diff -ur lin_tape-2.1.0/lin_tape_scsi_config.c lin_tape-2.1.0-3.10/lin_tape_scsi_config.c --- lin_tape-2.1.0/lin_tape_scsi_config.c 2013-06-12 23:07:31.000000000 +0200 +++ lin_tape-2.1.0-3.10/lin_tape_scsi_config.c 2013-08-25 14:24:13.053537972 +0200 @@ -3150,6 +3150,30 @@ return; } /* lin_tape_delete_tsm_pseudo() */ +static int tape_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, tape_read_proc, PDE_DATA(inode)); +} + +static int changer_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, changer_read_proc, PDE_DATA(inode)); +} + +static const struct file_operations tape_proc_fops = { + .open = tape_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static const struct file_operations changer_proc_fops = { + .open = changer_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + /******************************************************************************* * * * NAME: lin_tape_create_proc * @@ -3167,42 +3191,16 @@ DbgPrint(("lin_tape: lin_tape_create_proc entry\n")); WRITE_LOCK(&lin_tape_lock); - if(!tape_proc_entry) { - tape_proc_entry = - create_proc_entry("scsi/IBMtape", 0, NULL); - - if(!tape_proc_entry) { - DbgPrint(("lin_tape: cannot initialize "\ - "/proc/scsi/IBMtape\n")); - goto EXIT_LABEL; - } /* if */ - - tape_proc_entry->read_proc = tape_read_proc; -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) - tape_proc_entry->owner = THIS_MODULE; -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) - tape_proc_entry->get_info = NULL; -#endif -#endif + if (!proc_create("scsi/IBMtape", 0, NULL, &tape_proc_fops)) { + DbgPrint(("lin_tape: cannot initialize "\ + "/proc/scsi/IBMtape\n")); + goto EXIT_LABEL; } /* if */ - if(!changer_proc_entry) { - changer_proc_entry = - create_proc_entry("scsi/IBMchanger", 0, NULL); - - if(!changer_proc_entry) { - DbgPrint(("lin_tape: cannot initialize "\ - "/proc/scsi/IBMchanger\n")); - goto EXIT_LABEL; - } /* if */ - - changer_proc_entry->read_proc = changer_read_proc; -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) - changer_proc_entry->owner = THIS_MODULE; -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) - changer_proc_entry->get_info = NULL; -#endif -#endif + if (!proc_create("scsi/IBMchanger", 0, NULL, &changer_proc_fops)) { + DbgPrint(("lin_tape: cannot initialize "\ + "/proc/scsi/IBMchanger\n")); + goto EXIT_LABEL; } /* if */ EXIT_LABEL: @@ -3229,15 +3227,8 @@ { WRITE_LOCK(&lin_tape_lock); - if(tape_proc_entry) { - remove_proc_entry("scsi/IBMtape", NULL); - tape_proc_entry = NULL; - } /* if */ - - if(changer_proc_entry) { - remove_proc_entry("scsi/IBMchanger", NULL); - changer_proc_entry = NULL; - } /* if */ + remove_proc_entry("scsi/IBMtape", NULL); + remove_proc_entry("scsi/IBMchanger", NULL); WRITE_UNLOCK(&lin_tape_lock); @@ -3262,52 +3253,36 @@ * RETURNS: 0 on success or error * * * *******************************************************************************/ - -static int tape_read_proc(char* buffer, char** start, off_t offset, int length, - int* eof, void* data) +static int tape_read_proc(struct seq_file *m, void* data) { - int buf_offset = 0, i = 0, start_dev = 0, found = 0, linelen = 0; - unchar* model = NULL, * pre_buf = NULL; - unchar temp_buf[96]; + int i = 0, found = 0; + unchar* model = NULL; char* sn = NULL; boolean tape_des_locked = False; DbgPrint(("lin_tape: tape_read_proc entry\n")); model = kmalloc(12, GFP_KERNEL); - pre_buf = kmalloc(ONE_K / 4, GFP_KERNEL); sn = kmalloc(MaxSerialNumberSize + 1, GFP_KERNEL); - if(!model || !pre_buf || !sn || !buffer || !start || !eof) { - if(start) *start = buffer; - if(eof) *eof = True; + if(!model || !sn) { goto EXIT_LABEL; } /* if */ - memset(temp_buf, '\0', 96); memset(model, '\0', 12); - memset(pre_buf, '\0', ONE_K / 4); memset(sn, '\0', MaxSerialNumberSize + 1); i = 0; - if(!offset && rd_pc_initial(buffer, &buf_offset, length, start, False)) - goto EXIT_LABEL; - - if(rd_pc_start_dev(&start_dev, eof, offset, buffer, &buf_offset, False)) - goto EXIT_LABEL; + rd_pc_initial(m, False); READ_LOCK(&tape_des_lock); tape_des_locked = True; if(!tape_devs) { - *eof = True; - if(buf_offset == length) buf_offset--; - buf_offset += sprintf(&buffer[buf_offset], "\n"); - *start = buffer; goto EXIT_LABEL; } /* if */ - for(i = start_dev; i < MaxLinTapeDevices; i++) { + for(i = 0; i < MaxLinTapeDevices; i++) { if(!tape_devs[i] || !tape_devs[i]->dev_obj) continue; found = False; @@ -3326,8 +3301,7 @@ sn[strlen(sn) - 1] == '\t')) sn[strlen(sn) - 1] = '\0'; - linelen = snprintf(pre_buf, ONE_K / 4, - "\n%-8d%-12s%-18s%-16s%-16s%-10s", + seq_printf(m, "%-8d%-12s%-18s%-16s", i, model, @@ -3335,12 +3309,12 @@ tape_devs[i]->serial_num_len ? sn : "NA", tape_devs[i]->ghost_device ? "" : - found ? tape_devs[i]->pname : "NA", + found ? tape_devs[i]->pname : "NA"); - tape_devs[i]->ghost_device ? "" : - scsi_addr_str(tape_devs[i], temp_buf, - False), + if (!tape_devs[i]->ghost_device) + scsi_addr_str(tape_devs[i], m, False); + seq_printf(m, "%-10s\n", tape_devs[i]->ghost_device ? "" : !found ? "NA" : !tape_devs[i]->serial_num_len ? "NA" : @@ -3349,45 +3323,23 @@ tape_devs[i]->isPrimary ? "Primary" : "Alternate"); - if(buf_offset > length) { - buf_offset = length; - break; - } else if(buf_offset + linelen >= length) { - memset(&buffer[buf_offset], ' ', length - buf_offset); - buf_offset = length; - break; - } /* if */ - - buf_offset += sprintf(&buffer[buf_offset], "%s", pre_buf); tape_devs[i]->proc_read = True; } /* for */ tape_des_locked = False; READ_UNLOCK(&tape_des_lock); - if(i == start_dev || i >= MaxLinTapeDevices) { - if(buf_offset == length) buf_offset--; - buf_offset += sprintf(&buffer[buf_offset], "\n"); - *eof = True; - if(i >= MaxLinTapeDevices) *start = buffer; - goto EXIT_LABEL; - } /* if */ - - *start = buffer; - EXIT_LABEL: - if(pre_buf) kfree(pre_buf); if(model) kfree(model); if(sn) kfree(sn); if(tape_des_locked) READ_UNLOCK(&tape_des_lock); tape_des_locked = False; - if(buf_offset == 1 && *eof) buf_offset = 0; - DbgPrint(("tape_read_proc exit: %d\n", buf_offset)); + DbgPrint(("tape_read_proc exit:\n")); - return buf_offset; + return 0; } /* tape_read_proc() */ /******************************************************************************* @@ -3409,12 +3361,10 @@ * * *******************************************************************************/ -static int changer_read_proc(char* buffer, char** start, off_t offset, - int length, int* eof, void* data) +static int changer_read_proc(struct seq_file *m, void* data) { - int buf_offset = 0, i = 0, start_dev = 0, found = 0, linelen = 0; - unchar* model = NULL, * pre_buf = NULL; - unchar temp_buf[96]; + int i = 0, found = 0; + unchar* model = NULL; char* sn = NULL; boolean changer_des_locked = False; @@ -3423,37 +3373,24 @@ i = 0; model = kmalloc(12, GFP_KERNEL); - pre_buf = kmalloc(ONE_K / 4, GFP_KERNEL); sn = kmalloc(MaxSerialNumberSize + 1, GFP_KERNEL); - if(!model || !pre_buf || !sn || !buffer || !start || !eof) { - if(start) *start = buffer; - if(eof) *eof = True; + if(!model || !sn) { goto EXIT_LABEL; } /* if */ - memset(temp_buf, '\0', 96); memset(model, '\0', 12); - memset(pre_buf, '\0', ONE_K / 4); memset(sn, '\0', MaxSerialNumberSize + 1); - if(!offset && rd_pc_initial(buffer, &buf_offset, length, start, True)) - goto EXIT_LABEL; - - if(rd_pc_start_dev(&start_dev, eof, offset, buffer, &buf_offset, True)) - goto EXIT_LABEL; + rd_pc_initial(m, True); READ_LOCK(&changer_des_lock); changer_des_locked = True; if(!changer_devs) { - *eof = True; - if(buf_offset == length) buf_offset--; - buf_offset += sprintf(&buffer[buf_offset], "\n"); - *start = buffer; goto EXIT_LABEL; } /* if */ - for(i = start_dev; i < MaxLinTapeChangerDevices; i++) { + for(i = 0; i < MaxLinTapeChangerDevices; i++) { if(!changer_devs[i] || !changer_devs[i]->dev_obj) continue; found = False; @@ -3472,8 +3409,7 @@ sn[strlen(sn) - 1] == '\t')) sn[strlen(sn) - 1] = '\0'; - linelen = snprintf(pre_buf, ONE_K / 4, - "\n%-8d%-12s%-18s%-16s%-16s%-10s", + seq_printf(m, "%-8d%-12s%-18s%-16s", i, model, @@ -3481,14 +3417,12 @@ changer_devs[i]->serial_num_len ? sn : "NA", changer_devs[i]->ghost_device ? "" : - found ? changer_devs[i]->pname : "NA", + found ? changer_devs[i]->pname : "NA"); - changer_devs[i]->ghost_device ? "" : - scsi_addr_str((struct tape_descriptor*) - changer_devs[i], - temp_buf, - True), + if (!changer_devs[i]->ghost_device) + scsi_addr_str((struct tape_descriptor*)changer_devs[i], m, True); + seq_printf(m, "%-10s\n", changer_devs[i]->ghost_device ? "" : !found ? "NA" : changer_devs[i]->chg_id == IBM_3590 @@ -3498,45 +3432,23 @@ changer_devs[i]->isPrimary ? "Primary" : "Alternate"); - if(buf_offset > length) { - buf_offset = length; - break; - } else if(buf_offset + linelen >= length) { - memset(&buffer[buf_offset], ' ', length - buf_offset); - buf_offset = length; - break; - } /* if */ - - buf_offset += sprintf(&buffer[buf_offset], "%s", pre_buf); changer_devs[i]->proc_read = True; } /* for */ changer_des_locked = False; READ_UNLOCK(&changer_des_lock); - if(i == start_dev || i >= MaxLinTapeChangerDevices) { - if(buf_offset == length) buf_offset--; - buf_offset += sprintf(&buffer[buf_offset], "\n"); - *eof = True; - if(i >= MaxLinTapeChangerDevices) *start = buffer; - goto EXIT_LABEL; - } /* if */ - - *start = buffer; - EXIT_LABEL: if(model) kfree(model); - if(pre_buf) kfree(pre_buf); if(sn) kfree(sn); if(changer_des_locked) READ_UNLOCK(&changer_des_lock); changer_des_locked = False; - if(buf_offset == 1 && *eof) buf_offset = 0; - DbgPrint(("changer_read_proc exit: %d\n", buf_offset)); + DbgPrint(("changer_read_proc exit\n")); - return buf_offset; + return 0; } /* changer_read_proc() */ /******************************************************************************* @@ -3557,15 +3469,12 @@ * * *******************************************************************************/ -int rd_pc_initial(char* buffer, int* buf_offset, int length, char** start, - boolean chg) +int rd_pc_initial(struct seq_file *m, boolean chg) { - int rc = 1, count = 0, i = 0, max_devices = 0; - char tmp_buf[96]; + int i = 0, max_devices = 0; DbgPrint(("rd_pc_initial entry\n")); - memset(tmp_buf, '\0', 96); max_devices = chg ? MaxLinTapeChangerDevices : MaxLinTapeDevices; /* set proc_read flag for each logical device to false */ @@ -3580,47 +3489,14 @@ } /* if */ WRITE_UNLOCK(chg ? &changer_des_lock : &tape_des_lock); - count = sprintf(tmp_buf, "lin_tape version: %s", LIN_TAPE_VERSION); - if(count > length) goto EXIT_LABEL; - - count = sprintf(buffer, "lin_tape version: %s", LIN_TAPE_VERSION); - *buf_offset = count; - - count = sprintf(tmp_buf, "\nlin_tape major number: %d", lin_tape_major); - if(*buf_offset + count > length) goto EXIT_LABEL; - - count = sprintf(buffer + *buf_offset, - "\nlin_tape major number: %d", lin_tape_major); - *buf_offset += count; - - count = sprintf(tmp_buf, "\nAttached %s Devices:", - chg ? "Changer" : "Tape"); - if(*buf_offset + count > length) goto EXIT_LABEL; - - count = sprintf(buffer + *buf_offset, "\nAttached %s Devices:", - chg ? "Changer" : "Tape"); - *buf_offset += count; - - count = sprintf(tmp_buf, "\n%-8s%-12s%-18s%-16s%-16s%-10s", - "Number", "model", "SN", "HBA", "SCSI", "FO Path"); - if(*buf_offset + count > length) goto EXIT_LABEL; - - count = sprintf(buffer + *buf_offset, "\n%-8s%-12s%-18s%-16s%-16s%-10s", + seq_printf(m, "lin_tape version: %s\n", LIN_TAPE_VERSION); + seq_printf(m, "lin_tape major number: %d\n", lin_tape_major); + seq_printf(m, "Attached %s Devices:\n", chg ? "Changer" : "Tape"); + seq_printf(m, "%-8s%-12s%-18s%-16s%-16s%-10s\n", "Number", "model", "SN", "HBA", "SCSI", "FO Path"); - *buf_offset += count; - - rc = 0; -EXIT_LABEL: - - if(rc) { - memset(buffer + *buf_offset, ' ', length - *buf_offset); - *buf_offset = length; - *start = buffer; - } /* if */ - - DbgPrint(("rd_pc_initial exit: %d\n", rc)); - return rc; + DbgPrint(("rd_pc_initial exit\n")); + return 0; } /* rd_pc_initial() */ /******************************************************************************* @@ -3642,8 +3518,8 @@ * * *******************************************************************************/ -int rd_pc_start_dev(int* start_dev, int* eof, off_t offset, char* buffer, - int* buf_offset, boolean chg) +int rd_pc_start_dev(int* start_dev, int* eof, off_t offset, struct seq_file *m, + boolean chg) { int found = False, rc = 0, i = 0, max_devices = 0; @@ -3678,7 +3554,7 @@ if(*start_dev >= max_devices) { *eof = True; - *buf_offset += sprintf(&buffer[*buf_offset], "\n"); + seq_printf(m, "\n"); rc = 1; goto EXIT_LABEL; } /* if */ @@ -3705,17 +3581,16 @@ * * *******************************************************************************/ -char* scsi_addr_str(struct tape_descriptor* drv, char* buffer, boolean cgr) +void scsi_addr_str(struct tape_descriptor* drv, struct seq_file *m, boolean cgr) { struct changer_descriptor* chg = (struct changer_descriptor*)drv; if(cgr) - sprintf(buffer, "%d:%d:%d:%d", + seq_printf(m, "%d:%d:%d:%d", chg->host, chg->channel, chg->target, chg->lun); else - sprintf(buffer, "%d:%d:%d:%d", + seq_printf(m, "%d:%d:%d:%d", drv->host, drv->channel, drv->target, drv->lun); - return buffer; } /* scsi_addr_str() */ /******************************************************************************* diff -ur lin_tape-2.1.0/lin_tape_scsi_config.h lin_tape-2.1.0-3.10/lin_tape_scsi_config.h --- lin_tape-2.1.0/lin_tape_scsi_config.h 2013-06-12 23:07:31.000000000 +0200 +++ lin_tape-2.1.0-3.10/lin_tape_scsi_config.h 2013-08-25 14:22:14.635373745 +0200 @@ -178,14 +178,11 @@ #endif static void lin_tape_rescan(struct device *); -static int tape_read_proc(char *, char **, off_t, int, int *, void *); -int rd_pc_initial(char* buffer, int* buf_offset, int length, char** start, - boolean chg); -int rd_pc_start_dev(int* start_dev, int* eof, off_t offset, char* buffer, - int* buf_offset, boolean chg); -char* scsi_addr_str(struct tape_descriptor* drv, char* buffer, boolean cgr); +static int tape_read_proc(struct seq_file *, void *); +int rd_pc_initial(struct seq_file *, boolean chg); +void scsi_addr_str(struct tape_descriptor* drv, struct seq_file *m, boolean cgr); -static int changer_read_proc(char *, char **, off_t, int, int *, void *); +static int changer_read_proc(struct seq_file *, void *); /* global variables */ static unchar lin_tape_cleanup_module = 0; @@ -222,9 +219,6 @@ atomic_t tsm_tp_open = {0}; static unsigned int lin_tape_major; -static struct proc_dir_entry *tape_proc_entry = NULL; -static struct proc_dir_entry *changer_proc_entry = NULL; - #if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0) rwlock_t hba_lock = RW_LOCK_UNLOCKED; #else