1 diff -ur lin_tape-2.1.0/lin_tape_scsi_config.c lin_tape-2.1.0-3.10/lin_tape_scsi_config.c
2 --- lin_tape-2.1.0/lin_tape_scsi_config.c 2013-06-12 23:07:31.000000000 +0200
3 +++ lin_tape-2.1.0-3.10/lin_tape_scsi_config.c 2013-08-25 14:24:13.053537972 +0200
6 } /* lin_tape_delete_tsm_pseudo() */
8 +static int tape_proc_open(struct inode *inode, struct file *file)
10 + return single_open(file, tape_read_proc, PDE_DATA(inode));
13 +static int changer_proc_open(struct inode *inode, struct file *file)
15 + return single_open(file, changer_read_proc, PDE_DATA(inode));
18 +static const struct file_operations tape_proc_fops = {
19 + .open = tape_proc_open,
21 + .llseek = seq_lseek,
22 + .release = single_release,
25 +static const struct file_operations changer_proc_fops = {
26 + .open = changer_proc_open,
28 + .llseek = seq_lseek,
29 + .release = single_release,
32 /*******************************************************************************
34 * NAME: lin_tape_create_proc *
35 @@ -3167,42 +3191,16 @@
36 DbgPrint(("lin_tape: lin_tape_create_proc entry\n"));
38 WRITE_LOCK(&lin_tape_lock);
39 - if(!tape_proc_entry) {
41 - create_proc_entry("scsi/IBMtape", 0, NULL);
43 - if(!tape_proc_entry) {
44 - DbgPrint(("lin_tape: cannot initialize "\
45 - "/proc/scsi/IBMtape\n"));
49 - tape_proc_entry->read_proc = tape_read_proc;
50 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
51 - tape_proc_entry->owner = THIS_MODULE;
52 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
53 - tape_proc_entry->get_info = NULL;
56 + if (!proc_create("scsi/IBMtape", 0, NULL, &tape_proc_fops)) {
57 + DbgPrint(("lin_tape: cannot initialize "\
58 + "/proc/scsi/IBMtape\n"));
62 - if(!changer_proc_entry) {
63 - changer_proc_entry =
64 - create_proc_entry("scsi/IBMchanger", 0, NULL);
66 - if(!changer_proc_entry) {
67 - DbgPrint(("lin_tape: cannot initialize "\
68 - "/proc/scsi/IBMchanger\n"));
72 - changer_proc_entry->read_proc = changer_read_proc;
73 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
74 - changer_proc_entry->owner = THIS_MODULE;
75 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
76 - changer_proc_entry->get_info = NULL;
79 + if (!proc_create("scsi/IBMchanger", 0, NULL, &changer_proc_fops)) {
80 + DbgPrint(("lin_tape: cannot initialize "\
81 + "/proc/scsi/IBMchanger\n"));
86 @@ -3229,15 +3227,8 @@
88 WRITE_LOCK(&lin_tape_lock);
90 - if(tape_proc_entry) {
91 - remove_proc_entry("scsi/IBMtape", NULL);
92 - tape_proc_entry = NULL;
95 - if(changer_proc_entry) {
96 - remove_proc_entry("scsi/IBMchanger", NULL);
97 - changer_proc_entry = NULL;
99 + remove_proc_entry("scsi/IBMtape", NULL);
100 + remove_proc_entry("scsi/IBMchanger", NULL);
102 WRITE_UNLOCK(&lin_tape_lock);
104 @@ -3262,52 +3253,36 @@
105 * RETURNS: 0 on success or error *
107 *******************************************************************************/
109 -static int tape_read_proc(char* buffer, char** start, off_t offset, int length,
110 - int* eof, void* data)
111 +static int tape_read_proc(struct seq_file *m, void* data)
113 - int buf_offset = 0, i = 0, start_dev = 0, found = 0, linelen = 0;
114 - unchar* model = NULL, * pre_buf = NULL;
115 - unchar temp_buf[96];
116 + int i = 0, found = 0;
117 + unchar* model = NULL;
119 boolean tape_des_locked = False;
121 DbgPrint(("lin_tape: tape_read_proc entry\n"));
123 model = kmalloc(12, GFP_KERNEL);
124 - pre_buf = kmalloc(ONE_K / 4, GFP_KERNEL);
125 sn = kmalloc(MaxSerialNumberSize + 1, GFP_KERNEL);
126 - if(!model || !pre_buf || !sn || !buffer || !start || !eof) {
127 - if(start) *start = buffer;
128 - if(eof) *eof = True;
129 + if(!model || !sn) {
133 - memset(temp_buf, '\0', 96);
134 memset(model, '\0', 12);
135 - memset(pre_buf, '\0', ONE_K / 4);
136 memset(sn, '\0', MaxSerialNumberSize + 1);
140 - if(!offset && rd_pc_initial(buffer, &buf_offset, length, start, False))
143 - if(rd_pc_start_dev(&start_dev, eof, offset, buffer, &buf_offset, False))
145 + rd_pc_initial(m, False);
147 READ_LOCK(&tape_des_lock);
148 tape_des_locked = True;
152 - if(buf_offset == length) buf_offset--;
153 - buf_offset += sprintf(&buffer[buf_offset], "\n");
158 - for(i = start_dev; i < MaxLinTapeDevices; i++) {
159 + for(i = 0; i < MaxLinTapeDevices; i++) {
160 if(!tape_devs[i] || !tape_devs[i]->dev_obj) continue;
163 @@ -3326,8 +3301,7 @@
164 sn[strlen(sn) - 1] == '\t'))
165 sn[strlen(sn) - 1] = '\0';
167 - linelen = snprintf(pre_buf, ONE_K / 4,
168 - "\n%-8d%-12s%-18s%-16s%-16s%-10s",
169 + seq_printf(m, "%-8d%-12s%-18s%-16s",
173 @@ -3335,12 +3309,12 @@
174 tape_devs[i]->serial_num_len ? sn : "NA",
176 tape_devs[i]->ghost_device ? "" :
177 - found ? tape_devs[i]->pname : "NA",
178 + found ? tape_devs[i]->pname : "NA");
180 - tape_devs[i]->ghost_device ? "" :
181 - scsi_addr_str(tape_devs[i], temp_buf,
183 + if (!tape_devs[i]->ghost_device)
184 + scsi_addr_str(tape_devs[i], m, False);
186 + seq_printf(m, "%-10s\n",
187 tape_devs[i]->ghost_device ? "" :
189 !tape_devs[i]->serial_num_len ? "NA" :
190 @@ -3349,45 +3323,23 @@
191 tape_devs[i]->isPrimary ? "Primary" :
194 - if(buf_offset > length) {
195 - buf_offset = length;
197 - } else if(buf_offset + linelen >= length) {
198 - memset(&buffer[buf_offset], ' ', length - buf_offset);
199 - buf_offset = length;
203 - buf_offset += sprintf(&buffer[buf_offset], "%s", pre_buf);
204 tape_devs[i]->proc_read = True;
207 tape_des_locked = False;
208 READ_UNLOCK(&tape_des_lock);
210 - if(i == start_dev || i >= MaxLinTapeDevices) {
211 - if(buf_offset == length) buf_offset--;
212 - buf_offset += sprintf(&buffer[buf_offset], "\n");
214 - if(i >= MaxLinTapeDevices) *start = buffer;
222 - if(pre_buf) kfree(pre_buf);
223 if(model) kfree(model);
226 if(tape_des_locked) READ_UNLOCK(&tape_des_lock);
227 tape_des_locked = False;
229 - if(buf_offset == 1 && *eof) buf_offset = 0;
230 - DbgPrint(("tape_read_proc exit: %d\n", buf_offset));
231 + DbgPrint(("tape_read_proc exit:\n"));
235 } /* tape_read_proc() */
237 /*******************************************************************************
238 @@ -3409,12 +3361,10 @@
240 *******************************************************************************/
242 -static int changer_read_proc(char* buffer, char** start, off_t offset,
243 - int length, int* eof, void* data)
244 +static int changer_read_proc(struct seq_file *m, void* data)
246 - int buf_offset = 0, i = 0, start_dev = 0, found = 0, linelen = 0;
247 - unchar* model = NULL, * pre_buf = NULL;
248 - unchar temp_buf[96];
249 + int i = 0, found = 0;
250 + unchar* model = NULL;
252 boolean changer_des_locked = False;
254 @@ -3423,37 +3373,24 @@
257 model = kmalloc(12, GFP_KERNEL);
258 - pre_buf = kmalloc(ONE_K / 4, GFP_KERNEL);
259 sn = kmalloc(MaxSerialNumberSize + 1, GFP_KERNEL);
260 - if(!model || !pre_buf || !sn || !buffer || !start || !eof) {
261 - if(start) *start = buffer;
262 - if(eof) *eof = True;
263 + if(!model || !sn) {
267 - memset(temp_buf, '\0', 96);
268 memset(model, '\0', 12);
269 - memset(pre_buf, '\0', ONE_K / 4);
270 memset(sn, '\0', MaxSerialNumberSize + 1);
272 - if(!offset && rd_pc_initial(buffer, &buf_offset, length, start, True))
275 - if(rd_pc_start_dev(&start_dev, eof, offset, buffer, &buf_offset, True))
277 + rd_pc_initial(m, True);
279 READ_LOCK(&changer_des_lock);
280 changer_des_locked = True;
284 - if(buf_offset == length) buf_offset--;
285 - buf_offset += sprintf(&buffer[buf_offset], "\n");
290 - for(i = start_dev; i < MaxLinTapeChangerDevices; i++) {
291 + for(i = 0; i < MaxLinTapeChangerDevices; i++) {
292 if(!changer_devs[i] || !changer_devs[i]->dev_obj) continue;
295 @@ -3472,8 +3409,7 @@
296 sn[strlen(sn) - 1] == '\t'))
297 sn[strlen(sn) - 1] = '\0';
299 - linelen = snprintf(pre_buf, ONE_K / 4,
300 - "\n%-8d%-12s%-18s%-16s%-16s%-10s",
301 + seq_printf(m, "%-8d%-12s%-18s%-16s",
305 @@ -3481,14 +3417,12 @@
306 changer_devs[i]->serial_num_len ? sn : "NA",
308 changer_devs[i]->ghost_device ? "" :
309 - found ? changer_devs[i]->pname : "NA",
310 + found ? changer_devs[i]->pname : "NA");
312 - changer_devs[i]->ghost_device ? "" :
313 - scsi_addr_str((struct tape_descriptor*)
317 + if (!changer_devs[i]->ghost_device)
318 + scsi_addr_str((struct tape_descriptor*)changer_devs[i], m, True);
320 + seq_printf(m, "%-10s\n",
321 changer_devs[i]->ghost_device ? "" :
323 changer_devs[i]->chg_id == IBM_3590
324 @@ -3498,45 +3432,23 @@
325 changer_devs[i]->isPrimary ? "Primary" :
328 - if(buf_offset > length) {
329 - buf_offset = length;
331 - } else if(buf_offset + linelen >= length) {
332 - memset(&buffer[buf_offset], ' ', length - buf_offset);
333 - buf_offset = length;
337 - buf_offset += sprintf(&buffer[buf_offset], "%s", pre_buf);
338 changer_devs[i]->proc_read = True;
341 changer_des_locked = False;
342 READ_UNLOCK(&changer_des_lock);
344 - if(i == start_dev || i >= MaxLinTapeChangerDevices) {
345 - if(buf_offset == length) buf_offset--;
346 - buf_offset += sprintf(&buffer[buf_offset], "\n");
348 - if(i >= MaxLinTapeChangerDevices) *start = buffer;
356 if(model) kfree(model);
357 - if(pre_buf) kfree(pre_buf);
360 if(changer_des_locked) READ_UNLOCK(&changer_des_lock);
361 changer_des_locked = False;
363 - if(buf_offset == 1 && *eof) buf_offset = 0;
364 - DbgPrint(("changer_read_proc exit: %d\n", buf_offset));
365 + DbgPrint(("changer_read_proc exit\n"));
369 } /* changer_read_proc() */
371 /*******************************************************************************
372 @@ -3557,15 +3469,12 @@
374 *******************************************************************************/
376 -int rd_pc_initial(char* buffer, int* buf_offset, int length, char** start,
378 +int rd_pc_initial(struct seq_file *m, boolean chg)
380 - int rc = 1, count = 0, i = 0, max_devices = 0;
382 + int i = 0, max_devices = 0;
384 DbgPrint(("rd_pc_initial entry\n"));
386 - memset(tmp_buf, '\0', 96);
387 max_devices = chg ? MaxLinTapeChangerDevices : MaxLinTapeDevices;
389 /* set proc_read flag for each logical device to false */
390 @@ -3580,47 +3489,14 @@
392 WRITE_UNLOCK(chg ? &changer_des_lock : &tape_des_lock);
394 - count = sprintf(tmp_buf, "lin_tape version: %s", LIN_TAPE_VERSION);
395 - if(count > length) goto EXIT_LABEL;
397 - count = sprintf(buffer, "lin_tape version: %s", LIN_TAPE_VERSION);
398 - *buf_offset = count;
400 - count = sprintf(tmp_buf, "\nlin_tape major number: %d", lin_tape_major);
401 - if(*buf_offset + count > length) goto EXIT_LABEL;
403 - count = sprintf(buffer + *buf_offset,
404 - "\nlin_tape major number: %d", lin_tape_major);
405 - *buf_offset += count;
407 - count = sprintf(tmp_buf, "\nAttached %s Devices:",
408 - chg ? "Changer" : "Tape");
409 - if(*buf_offset + count > length) goto EXIT_LABEL;
411 - count = sprintf(buffer + *buf_offset, "\nAttached %s Devices:",
412 - chg ? "Changer" : "Tape");
413 - *buf_offset += count;
415 - count = sprintf(tmp_buf, "\n%-8s%-12s%-18s%-16s%-16s%-10s",
416 - "Number", "model", "SN", "HBA", "SCSI", "FO Path");
417 - if(*buf_offset + count > length) goto EXIT_LABEL;
419 - count = sprintf(buffer + *buf_offset, "\n%-8s%-12s%-18s%-16s%-16s%-10s",
420 + seq_printf(m, "lin_tape version: %s\n", LIN_TAPE_VERSION);
421 + seq_printf(m, "lin_tape major number: %d\n", lin_tape_major);
422 + seq_printf(m, "Attached %s Devices:\n", chg ? "Changer" : "Tape");
423 + seq_printf(m, "%-8s%-12s%-18s%-16s%-16s%-10s\n",
424 "Number", "model", "SN", "HBA", "SCSI", "FO Path");
425 - *buf_offset += count;
432 - memset(buffer + *buf_offset, ' ', length - *buf_offset);
433 - *buf_offset = length;
437 - DbgPrint(("rd_pc_initial exit: %d\n", rc));
439 + DbgPrint(("rd_pc_initial exit\n"));
441 } /* rd_pc_initial() */
443 /*******************************************************************************
444 @@ -3642,8 +3518,8 @@
446 *******************************************************************************/
448 -int rd_pc_start_dev(int* start_dev, int* eof, off_t offset, char* buffer,
449 - int* buf_offset, boolean chg)
450 +int rd_pc_start_dev(int* start_dev, int* eof, off_t offset, struct seq_file *m,
453 int found = False, rc = 0, i = 0, max_devices = 0;
455 @@ -3678,7 +3554,7 @@
457 if(*start_dev >= max_devices) {
459 - *buf_offset += sprintf(&buffer[*buf_offset], "\n");
460 + seq_printf(m, "\n");
464 @@ -3705,17 +3581,16 @@
466 *******************************************************************************/
468 -char* scsi_addr_str(struct tape_descriptor* drv, char* buffer, boolean cgr)
469 +void scsi_addr_str(struct tape_descriptor* drv, struct seq_file *m, boolean cgr)
471 struct changer_descriptor* chg = (struct changer_descriptor*)drv;
474 - sprintf(buffer, "%d:%d:%d:%d",
475 + seq_printf(m, "%d:%d:%d:%d",
476 chg->host, chg->channel, chg->target, chg->lun);
478 - sprintf(buffer, "%d:%d:%d:%d",
479 + seq_printf(m, "%d:%d:%d:%d",
480 drv->host, drv->channel, drv->target, drv->lun);
482 } /* scsi_addr_str() */
484 /*******************************************************************************
485 diff -ur lin_tape-2.1.0/lin_tape_scsi_config.h lin_tape-2.1.0-3.10/lin_tape_scsi_config.h
486 --- lin_tape-2.1.0/lin_tape_scsi_config.h 2013-06-12 23:07:31.000000000 +0200
487 +++ lin_tape-2.1.0-3.10/lin_tape_scsi_config.h 2013-08-25 14:22:14.635373745 +0200
488 @@ -178,14 +178,11 @@
490 static void lin_tape_rescan(struct device *);
492 -static int tape_read_proc(char *, char **, off_t, int, int *, void *);
493 -int rd_pc_initial(char* buffer, int* buf_offset, int length, char** start,
495 -int rd_pc_start_dev(int* start_dev, int* eof, off_t offset, char* buffer,
496 - int* buf_offset, boolean chg);
497 -char* scsi_addr_str(struct tape_descriptor* drv, char* buffer, boolean cgr);
498 +static int tape_read_proc(struct seq_file *, void *);
499 +int rd_pc_initial(struct seq_file *, boolean chg);
500 +void scsi_addr_str(struct tape_descriptor* drv, struct seq_file *m, boolean cgr);
502 -static int changer_read_proc(char *, char **, off_t, int, int *, void *);
503 +static int changer_read_proc(struct seq_file *, void *);
505 /* global variables */
506 static unchar lin_tape_cleanup_module = 0;
508 atomic_t tsm_tp_open = {0};
509 static unsigned int lin_tape_major;
511 -static struct proc_dir_entry *tape_proc_entry = NULL;
512 -static struct proc_dir_entry *changer_proc_entry = NULL;
514 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)
515 rwlock_t hba_lock = RW_LOCK_UNLOCKED;