summarylogtreecommitdiffstats
path: root/lt-ps-honor_system_file_allocate_all.patch
blob: bf466e3683bf7e9b721b684bb1964e56b14ab21d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
--- release/src/download/download_wrapper.cc	2015-08-08 16:01:49.000000000 +0100
+++ patched/src/download/download_wrapper.cc	2016-08-23 18:06:34.346151049 +0100
@@ -343,6 +343,8 @@ DownloadWrapper::receive_update_prioriti
       data()->mutable_high_priority()->insert((*itr)->range().first, (*itr)->range().second);
       break;
     default:
+      // Unset fallocate flag if priority of a file is Off.
+      (*itr)->unset_flags(File::flag_fallocate);
       break;
     }
   }
--- release/src/torrent/data/file.cc	2015-08-08 16:01:49.000000000 +0100
+++ patched/src/torrent/data/file.cc	2016-08-23 12:59:32.115952838 +0100
@@ -168,13 +168,14 @@ File::resize_file() {
   if (m_size == SocketFile(m_fd).size())
     return true;
 
-  // For now make it so that the fallocate flag indicates if we want
-  // to do potentially blocking allocation, while FS supported
-  // non-blocking allocation is done always.
-  int flags = SocketFile::flag_fallocate;
+  int flags = 0;
 
-  if (m_flags & flag_fallocate)
+  // Set FS supported non-blocking allocation flag and potentially
+  // blocking allocation flag if fallocate flag is set.
+  if (m_flags & flag_fallocate) {
+    flags |= SocketFile::flag_fallocate;
     flags |= SocketFile::flag_fallocate_blocking;
+  }
 
   return SocketFile(m_fd).set_size(m_size, flags);
 }
--- release/src/torrent/data/file_list.cc	2015-08-08 16:01:32.000000000 +0100
+++ patched/src/torrent/data/file_list.cc	2016-08-23 17:17:19.248826853 +0100
@@ -580,7 +580,12 @@ FileList::open_file(File* node, const Pa
     return false;
   }
 
-  return node->prepare(MemoryChunk::prot_read, 0);
+  // File allocation will be done if fallocate flag is set,
+  // create zero-length file otherwise.
+  if (node->has_flags(File::flag_fallocate))
+    return node->prepare(MemoryChunk::prot_write, 0);
+  else
+    return node->prepare(MemoryChunk::prot_read, 0);
 }
 
 MemoryChunk
--- release/src/torrent/download.cc	2015-08-08 16:01:49.000000000 +0100
+++ patched/src/torrent/download.cc	2016-08-23 18:14:20.843623816 +0100
@@ -131,9 +131,9 @@ Download::start(int flags) {
 
 //   file_list()->open(flags);
 
-  // If the FileList::open_no_create flag was not set, our new
-  // behavior is to create all zero-length files with
-  // flag_queued_create set.
+  // If the open_enable_fallocate or the FileList::open_no_create
+  // flag was not set, then create all zero-length files with
+  // flag_create_queued set.
   file_list()->open(flags & ~FileList::open_no_create);
 
   if (m_ptr->connection_type() == CONNECTION_INITIAL_SEED) {