relay.c (c3270e577c18b3d0e984c3371493205a4807db9d) | relay.c (68ab3d883a2df13f4b93a923bae3a287cbee29d3) |
---|---|
1/* 2 * Public API and common code for kernel->userspace relay file support. 3 * 4 * See Documentation/filesystems/relay.txt for an overview. 5 * 6 * Copyright (C) 2002-2005 - Tom Zanussi (zanussi@us.ibm.com), IBM Corp 7 * Copyright (C) 1999-2005 - Karim Yaghmour (karim@opersys.com) 8 * --- 51 unchanged lines hidden (view full) --- 60/* 61 * vm_ops for relay file mappings. 62 */ 63static struct vm_operations_struct relay_file_mmap_ops = { 64 .fault = relay_buf_fault, 65 .close = relay_file_mmap_close, 66}; 67 | 1/* 2 * Public API and common code for kernel->userspace relay file support. 3 * 4 * See Documentation/filesystems/relay.txt for an overview. 5 * 6 * Copyright (C) 2002-2005 - Tom Zanussi (zanussi@us.ibm.com), IBM Corp 7 * Copyright (C) 1999-2005 - Karim Yaghmour (karim@opersys.com) 8 * --- 51 unchanged lines hidden (view full) --- 60/* 61 * vm_ops for relay file mappings. 62 */ 63static struct vm_operations_struct relay_file_mmap_ops = { 64 .fault = relay_buf_fault, 65 .close = relay_file_mmap_close, 66}; 67 |
68/* 69 * allocate an array of pointers of struct page 70 */ 71static struct page **relay_alloc_page_array(unsigned int n_pages) 72{ 73 struct page **array; 74 size_t pa_size = n_pages * sizeof(struct page *); 75 76 if (pa_size > PAGE_SIZE) { 77 array = vmalloc(pa_size); 78 if (array) 79 memset(array, 0, pa_size); 80 } else { 81 array = kzalloc(pa_size, GFP_KERNEL); 82 } 83 return array; 84} 85 86/* 87 * free an array of pointers of struct page 88 */ 89static void relay_free_page_array(struct page **array) 90{ 91 if (is_vmalloc_addr(array)) 92 vfree(array); 93 else 94 kfree(array); 95} 96 |
|
68/** 69 * relay_mmap_buf: - mmap channel buffer to process address space 70 * @buf: relay channel buffer 71 * @vma: vm_area_struct describing memory to be mapped 72 * 73 * Returns 0 if ok, negative on error 74 * 75 * Caller should already have grabbed mmap_sem. --- 28 unchanged lines hidden (view full) --- 104static void *relay_alloc_buf(struct rchan_buf *buf, size_t *size) 105{ 106 void *mem; 107 unsigned int i, j, n_pages; 108 109 *size = PAGE_ALIGN(*size); 110 n_pages = *size >> PAGE_SHIFT; 111 | 97/** 98 * relay_mmap_buf: - mmap channel buffer to process address space 99 * @buf: relay channel buffer 100 * @vma: vm_area_struct describing memory to be mapped 101 * 102 * Returns 0 if ok, negative on error 103 * 104 * Caller should already have grabbed mmap_sem. --- 28 unchanged lines hidden (view full) --- 133static void *relay_alloc_buf(struct rchan_buf *buf, size_t *size) 134{ 135 void *mem; 136 unsigned int i, j, n_pages; 137 138 *size = PAGE_ALIGN(*size); 139 n_pages = *size >> PAGE_SHIFT; 140 |
112 buf->page_array = kcalloc(n_pages, sizeof(struct page *), GFP_KERNEL); | 141 buf->page_array = relay_alloc_page_array(n_pages); |
113 if (!buf->page_array) 114 return NULL; 115 116 for (i = 0; i < n_pages; i++) { 117 buf->page_array[i] = alloc_page(GFP_KERNEL); 118 if (unlikely(!buf->page_array[i])) 119 goto depopulate; 120 set_page_private(buf->page_array[i], (unsigned long)buf); --- 4 unchanged lines hidden (view full) --- 125 126 memset(mem, 0, *size); 127 buf->page_count = n_pages; 128 return mem; 129 130depopulate: 131 for (j = 0; j < i; j++) 132 __free_page(buf->page_array[j]); | 142 if (!buf->page_array) 143 return NULL; 144 145 for (i = 0; i < n_pages; i++) { 146 buf->page_array[i] = alloc_page(GFP_KERNEL); 147 if (unlikely(!buf->page_array[i])) 148 goto depopulate; 149 set_page_private(buf->page_array[i], (unsigned long)buf); --- 4 unchanged lines hidden (view full) --- 154 155 memset(mem, 0, *size); 156 buf->page_count = n_pages; 157 return mem; 158 159depopulate: 160 for (j = 0; j < i; j++) 161 __free_page(buf->page_array[j]); |
133 kfree(buf->page_array); | 162 relay_free_page_array(buf->page_array); |
134 return NULL; 135} 136 137/** 138 * relay_create_buf - allocate and initialize a channel buffer 139 * @chan: the relay channel 140 * 141 * Returns channel buffer if successful, %NULL otherwise. --- 42 unchanged lines hidden (view full) --- 184{ 185 struct rchan *chan = buf->chan; 186 unsigned int i; 187 188 if (likely(buf->start)) { 189 vunmap(buf->start); 190 for (i = 0; i < buf->page_count; i++) 191 __free_page(buf->page_array[i]); | 163 return NULL; 164} 165 166/** 167 * relay_create_buf - allocate and initialize a channel buffer 168 * @chan: the relay channel 169 * 170 * Returns channel buffer if successful, %NULL otherwise. --- 42 unchanged lines hidden (view full) --- 213{ 214 struct rchan *chan = buf->chan; 215 unsigned int i; 216 217 if (likely(buf->start)) { 218 vunmap(buf->start); 219 for (i = 0; i < buf->page_count; i++) 220 __free_page(buf->page_array[i]); |
192 kfree(buf->page_array); | 221 relay_free_page_array(buf->page_array); |
193 } 194 chan->buf[buf->cpu] = NULL; 195 kfree(buf->padding); 196 kfree(buf); 197 kref_put(&chan->kref, relay_destroy_channel); 198} 199 200/** --- 956 unchanged lines hidden (view full) --- 1157{ 1158 ssize_t spliced; 1159 int ret; 1160 int nonpad_ret = 0; 1161 1162 ret = 0; 1163 spliced = 0; 1164 | 222 } 223 chan->buf[buf->cpu] = NULL; 224 kfree(buf->padding); 225 kfree(buf); 226 kref_put(&chan->kref, relay_destroy_channel); 227} 228 229/** --- 956 unchanged lines hidden (view full) --- 1186{ 1187 ssize_t spliced; 1188 int ret; 1189 int nonpad_ret = 0; 1190 1191 ret = 0; 1192 spliced = 0; 1193 |
1165 while (len && !spliced) { | 1194 while (len) { |
1166 ret = subbuf_splice_actor(in, ppos, pipe, len, flags, &nonpad_ret); 1167 if (ret < 0) 1168 break; 1169 else if (!ret) { 1170 if (spliced) 1171 break; 1172 if (flags & SPLICE_F_NONBLOCK) { 1173 ret = -EAGAIN; --- 38 unchanged lines hidden --- | 1195 ret = subbuf_splice_actor(in, ppos, pipe, len, flags, &nonpad_ret); 1196 if (ret < 0) 1197 break; 1198 else if (!ret) { 1199 if (spliced) 1200 break; 1201 if (flags & SPLICE_F_NONBLOCK) { 1202 ret = -EAGAIN; --- 38 unchanged lines hidden --- |